package net.tycmc.cty.ctyms.timejob.iems.dao;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.dao.ITransactionDAO;
import net.tycmc.bulb.common.util.MapGetter;
import net.tycmc.bulb.common.util.StringUtil;
import net.tycmc.bulb.dbutil.global.GlobalDBVar;
import net.tycmc.cty.ctyms.timejob.common.ConfigEnum;
import net.tycmc.cty.ctyms.timejob.common.DateControl;
import net.tycmc.cty.ctyms.timejob.common.DateList;
import net.tycmc.cty.ctyms.timejob.common.EquipVersionCommon;
import net.tycmc.cty.ctyms.timejob.common.LogUtil;
import net.tycmc.cty.ctyms.timejob.common.SMSContentCfg;

/**
 * 故障报警相关表的DAO操作
 * 
 * @modify chengShiChao 增加故障报警状态初始化 2011-10-14
 * @modify chengShiChao 增加故障报警、保养提醒信息的短信发送和保养预测轮询 2011-10-22
 * @remark 故障报警、保养提醒的程序轮询时间间隔5分钟，保养预测程序轮询时间间隔1小时
 */
public class MtnFaultDao {
	private SMSInfoDAO smsInfoDAO;
	IBaseDAO baseDAO;
	private ITransactionDAO tranDAO;

	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}

	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}

	public ITransactionDAO getTranDAO() {
		return tranDAO;
	}

	public void setTranDAO(ITransactionDAO tranDAO) {
		this.tranDAO = tranDAO;
	}

	public SMSInfoDAO getSmsInfoDAO() {
		return smsInfoDAO;
	}

	public void setSmsInfoDAO(SMSInfoDAO smsInfoDAO) {
		this.smsInfoDAO = smsInfoDAO;
	}

	/**
	 * 测试连接CTYMS库
	 * 
	 * @return
	 */
	public List<Map<String, Object>> getTestCTYMS() {
		List<Map<String, Object>> rsList = new ArrayList<Map<String, Object>>();
		String sql = " SELECT CT_ID,CT_Value  FROM Card_Type ";

		try {
			rsList = this.getBaseDAO().execQuery(sql, new Object[] {});
		} catch (Exception ex) {
			System.out.print("MalfunctionDiagnosisDAO类的getTestCTYMS()方法有错误"
					+ ex.getMessage());
		}

		return rsList;
	}

	/**
	 * 故障信息轮询——————————————————begin
	 */
	/**
	 * 增加状态
	 * 
	 * @param MsgFS_MsgF_ID
	 * @return
	 */
	public boolean addFaultState(List<String> sqlList,List<Object[]> paramList,Map<String, Object> hm) {
		String VclID = MapGetter.getString(hm, "VehicleID");
		String MsgID = MapGetter.getString(hm, "MessageID");
		String MsgCID = MapGetter.getString(hm, "MFC_MessageID");
		String MsgTime = MapGetter.getString(hm, "MessageTime");
		String DBName = MapGetter.getString(hm, "MsgFS_DBName");
		String TableName = MapGetter.getString(hm, "TableName");
		String MsgLo = MapGetter.getString(hm, "MsgF_Lo");
		String MsgLa = MapGetter.getString(hm, "MsgF_La");
		String Position = MapGetter.getString(hm, "Position");
		//经纬度为空，初始为null,null
		if(!StringUtil.isValid(MsgLo)){
			MsgLo = null;
		}
		if(!StringUtil.isValid(MsgLa)){
			MsgLa = null;
		}
		boolean flag = false;
		// 判断该故障是否在提示信息表中已存在
		boolean isExist = this.isExist(1, DBName, TableName, MsgCID);
		if (!isExist) {
			// 若故障不存在则插入到提示信息表中
			try {
				/** 2013.03.27 haoyang 修改 begin */
				// 新增:
				String sql = "insert into Msg_Prompt(MsgP_VclID,MsgP_MsgID,MsgP_MsgCID,MsgP_MsgTime,MsgP_Type,MsgP_State,MsgP_DBName,MsgP_TableName,MsgP_CreateTime"
						+ ",MsgP_FltCode,MsgP_LampStatus,MsgP_DetailMsg,MsgP_SecTypeId,MsgP_SecTypeName,MsgP_FltAbbr,MsgP_Lo,MsgP_La,MsgP_Position)"
						+ "values(?,?,?,?,1,1,?,?,GETDATE(),?,?,?,?,?,?,?,?,?);";
				String vclId_fltCode_fltTimes = MapGetter.getString(hm, "fltTimes");//次数信息
				Map<String, Object> faultMsg = getFaultMsg(DBName, TableName,hm);
				if (faultMsg != null){
					sqlList.add(sql);
					paramList.add(new Object[] {VclID,MsgID,MsgCID,MsgTime,DBName,TableName,MapGetter.getString(faultMsg,"MsgP_FltCode"),
							MapGetter.getString(faultMsg,"MsgP_LampStatus"),MapGetter.getString(faultMsg,"MsgP_DetailMsg")+"<br/>"+vclId_fltCode_fltTimes,
							MapGetter.getString(faultMsg,"MsgP_SecTypeId"),MapGetter.getString(faultMsg,"MsgP_SecTypeName"),
							MapGetter.getString(faultMsg,"MsgP_FltAbbr"),MsgLo,MsgLa,"未知".equals(Position)?"":Position });
					flag = true;
				}
				
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		return flag;
	}

	/**
	 * 更新状态
	 * 
	 * @param FaultContent
	 * @return
	 */
	public boolean updateFaultState(List<String> sqlList,List<Object[]> paramList,Map<String, Object> hm) {
		String MsgFS_MsgFC_ID = MapGetter.getString(hm, "MFC_MessageID");
		String VehicleID = MapGetter.getString(hm, "VehicleID");
		String DBName = MapGetter.getString(hm, "MsgFS_DBName");
		String TableName = MapGetter.getString(hm, "TableName");
		String MsgPRelsTime = MapGetter.getString(hm, "MessageTime");
		String Position = MapGetter.getString(hm, "Position");

		if (!"A".equalsIgnoreCase(DBName) && !"B".equalsIgnoreCase(DBName)){
			return false;
		}else{
			String dbname = getDBName(DBName);
			int i = 0;
			try {
				String sql = "";
				String MsgCIDs_SQL = "";
				String spnName = "";
				String fmiName = "";
				if (DBName.equals("A")
						|| (DBName.equals("B") && TableName.equals("Flt"))) {
					sql = "select MsgFCo_FaultSPN,MsgFCo_FaultFMI from "
							+ dbname
							+ ".dbo.Msg_Flt left join "
							+ dbname
							+ ".dbo.Msg_Flt_Content on MsgFCo_MsgF_ID=MsgF_ID where MsgFCo_ID=?";
					MsgCIDs_SQL = "select MsgFCo_ID as MessageID from "
							+ dbname
							+ ".dbo.Msg_Flt inner join "
							+ dbname
							+ ".dbo.Msg_Flt_Content on MsgF_ID = MsgFCo_MsgF_ID where MsgF_Vcl_ID=?";
					spnName = "MsgFCo_FaultSPN";
					fmiName = "MsgFCo_FaultFMI";
				} else if (DBName.equals("B") && TableName.equals("Flt_UDS")) {
					sql = "select MsgFUC_FltFMI as MsgFCo_FaultFMI,MsgFUC_FltSPN as MsgFCo_FaultSPN from "
							+ dbname
							+ ".dbo.Msg_Flt_UDS "
							+ "left join "
							+ dbname
							+ ".dbo.Msg_Flt_UDS_Content on MsgFUC_MsgFU_ID = MsgFU_ID where MsgFUC_ID=?";
					MsgCIDs_SQL = "select MsgFUC_ID as MessageID from "
							+ dbname
							+ ".dbo.Msg_Flt_UDS inner join "
							+ dbname
							+ ".dbo.Msg_Flt_UDS_Content on MsgFU_ID = MsgFUC_MsgFU_ID where MsgFU_Vcl_ID=?";
					spnName = "MsgFUC_FltSPN";
					fmiName = "MsgFUC_FltFMI";
				} else {
					LogUtil.info(this.getClass().getName(),
							"1.2.1JOB---修改非现行故障是否成功：false  修改条数：" + i);
					return false;
				}

				List<Map<String, Object>> list_SPN_FMI = baseDAO.execQuery(sql,
						new Object[] { MsgFS_MsgFC_ID });
				String term = "";
				for (Map<String, Object> map : list_SPN_FMI) {
					if (MapGetter.getString(map, "MsgFCo_FaultSPN").equals("")
							|| MapGetter.getString(map, "MsgFCo_FaultFMI").equals(
									""))
						continue;
					if (!"".equals(term))
						term += " or ";
					term += "(" + spnName + "="
							+ MapGetter.getString(map, "MsgFCo_FaultSPN") + " and "
							+ fmiName + "="
							+ MapGetter.getString(map, "MsgFCo_FaultFMI") + ")";
				}

				StringBuffer strBuff = new StringBuffer();
				// strBuff.append("update Msg_Prompt set MsgP_State=3,MsgP_UpdateTime=GETDATE() where MsgP_Type=1 and MsgP_DBName=? and MsgP_TableName=? and MsgP_MsgCID in( ");
				// 2013.03.27 haoyang 修改:添加解除时间,解除方式,添加条件:只更新未解除的故障
				strBuff.append("update Msg_Prompt set MsgP_State=3,MsgP_UpdateTime=GETDATE(),MsgP_ReleaseTime=?"
						+ ",MsgP_ReleaseType = 1,MsgP_RelsCid=?  where MsgP_Type=1 and MsgP_State='1' and MsgP_DBName=? and MsgP_TableName=? " +
						" and MsgP_MsgTime<? and MsgP_MsgCID in( ");//添加条件：报警时间 小于 解除时间
				strBuff.append(MsgCIDs_SQL);
				strBuff.append(" and ( ");
				strBuff.append(term);
				strBuff.append(" ))");

				sqlList.add(strBuff.toString());
				paramList.add(new Object[] { MsgPRelsTime, MsgFS_MsgFC_ID, DBName,
						TableName,MsgPRelsTime, VehicleID });

			} catch (Exception e) {
				e.printStackTrace();
			}
			return true;
		}
	}

	/**
	 * 发送故障信息入口 	故障和解除
	 * @param sqlList
	 * @param paramList
	 * @param hm
	 * @param userList
	 * @param smsSendTimeList
	 * @param fltType
	 * @return
	 */
	public boolean sendFaultInfo(List<String> sqlList,List<Object[]> paramList,Map<String, Object> hm,
			List<Map<String, Object>> userList,List<String> smsSendTimeList,String fltType) {
		boolean flag = false;
		if(userList != null && userList.size() > 0){
			String VclID = MapGetter.getString(hm, "VehicleID");
			String MsgID = MapGetter.getString(hm, "MessageID");
			String MsgCID = MapGetter.getString(hm, "MFC_MessageID");
			String MsgTime = MapGetter.getString(hm, "MessageTime");
			String DBName = MapGetter.getString(hm, "MsgFS_DBName");
			String TableName = MapGetter.getString(hm, "TableName");
			String FaultCode = MapGetter.getString(hm, "FaultCode");
			String FaultContenti = MapGetter.getString(hm, "FltISM_ContentCN_Abbr");
			String ESN = MapGetter.getString(hm, "ESNNumber");
			String Position = MapGetter.getString(hm, "Position");
			String Color = MapGetter.getString(hm, "SysISM_CodeColorInfo");
			String VehicleContact = MapGetter.getString(hm, "VehicleContact");
			String Tel = MapGetter.getString(hm, "VehicleChargedMobile");
			//jinjiayu 20141126  3.6.9添加
			String fltLv = MapGetter.getString(hm, "SysISM_Level");//故障等级OEMTel,OEMName
			String fltRisk = MapGetter.getString(hm, "SysISM_Risk");//故障风险
			String oem = MapGetter.getString(hm, "OEMName");//生产厂家
			String oemtel = MapGetter.getString(hm, "OEMTel");//生产厂家电话
			
			if("无".equals(Color) || !StringUtil.isValid(Color)){
				Color = "其他";
			}else{
				Color = Color.substring(0,1);
			}
			Position = Position.replaceAll("省", "").replaceAll("市", "").replaceAll("附近", "").replaceAll(" ", "");
			if(Position.length()>15){
				Position = Position.substring(0, 15);
			}
			if("未知".equals(Position) || !StringUtil.isValid(Position)){
				Position = "暂无位置";
			}
			//判断短信是否发送过
			String isExist = "select * from SMS_SendRecord ";
			if(fltType.equals("1")){
				isExist += "  where SSR_MsgCID=? and (SSR_Type=1 or SSR_Type=17) and SSR_CreateType=? and SSR_DBName=?" +
					" and SSR_UsP_ID in ("+smsInfoDAO.getSMSUsersID(userList)+")";
			}else if(fltType.equals("7")){
				isExist += " where SSR_MsgCID=? and SSR_CreateType=? and SSR_DBName=?";
			}
			List<Map<String, Object>> num = baseDAO.execQuery(isExist,
					new Object[] { MsgCID, "1", DBName });
			if (num != null && num.size() > 0) {
				LogUtil.info(this.getClass().getName(), "JOB--现行故障短信是否发送成功：" + flag);
				return flag;
			}
			
			//判断故障是否发生过sql
			String[] sqls = getIsOccured_SQL(DBName,TableName,VclID,FaultCode,fltType);
			if(sqls == null ){
				return flag;
			}
			
			String serName = "";
			String serTel = "";
			boolean isSer = false;
			for(Map<String,Object> u : userList){
				if(MapGetter.getString(u, "SMSAS_IsServer").equals("true")){
					isSer = true;
					serName = MapGetter.getString(u, "UserName");
					serTel = MapGetter.getString(u, "Mobile");
					break;
				}
			}
			
			Map<String,Object> user = new HashMap<String, Object>();
			String SMSAS_SMSRels = "";	//短信--故障解除
			String UserID = "";			//人员ID
			String UserName = "";		//人员名称
			String SMSAS_SMSFltIsRed = "";//实时发送短信故障码—红色故障
			String SysISM_CodeColorInfo = "";//故障代码颜色
			String SMSFC_Type = "";		//类型（1：短信白名单；2：短信过滤；3：实时发送短信）
			String UserNames = "";
			String smsFltType = "";		//故障分类
			String smsFltisFoue = "";	//实时短信四级故障
			String smsFour = "";		//四级故障
			String SMSAS_SMSFltSendType = "";//短信--故障发送类型
			//开始时间
			String SMSAS_SMSFltSendBegin = "";
			String SMSAS_SMSFltSendEnd = "";
			
			String SC_SendTime_Bgn = "";
			String SC_SendTime_End = "";
			Map<String, Object> SMSMap = new HashMap<String, Object>();// 发送短信条件及sql语句
			// 获得设备所属机构Code值
			Map<String, Object> codeMap = new HashMap<String, Object>();
			// 获取设备组织机构
			String DBCode = "";
			// 获得设备号
			String VehicleNumber = "";
			// 时间
			String time = "";
			String SMSContent = "";
			String smsType = ""; 		//提示类型（1：常规提示；2：服务提示）
			String smsSendType = "";	//发送短信类型 
			for (int i = 0; i < userList.size(); i++) {
				user = userList.get(i);
				
				smsFltType = MapGetter.getString(user, "SMSAS_FltType");
				smsFltisFoue = MapGetter.getString(user, "SMSAS_SMSFltIsFour");
				smsType = MapGetter.getString(user, "SMSAS_Type");	
				SMSAS_SMSRels = MapGetter.getString(user, "SMSAS_SMSRels");
				if(fltType.equals("7") && !SMSAS_SMSRels.equals("true")){
					continue;
				}
				
				UserID = MapGetter.getString(user, "UserID");
				UserName = MapGetter.getString(user, "UserName");
				SMSAS_SMSFltIsRed = MapGetter.getString(user, "SMSAS_SMSFltIsRed");//实时发送短信故障码—红色故障（1：选中）
				SMSFC_Type = MapGetter.getString(user, "SMSFC_Type");
				smsFour = MapGetter.getString(user, "SMSAS_SMSFltFour");
				SysISM_CodeColorInfo = MapGetter.getString(hm, "SysISM_CodeColorInfo");
				//if(!(SMSAS_SMSFltIsRed.equals("true") && SysISM_CodeColorInfo.equals(ConfigEnum.FltCodeRed.getName())) && SMSFC_Type.equals("2")){
				if(SMSFC_Type.equals("2") && ( !(smsFltType.equals("2") && SMSAS_SMSFltIsRed.equals("true") && SysISM_CodeColorInfo.equals(ConfigEnum.FltCodeRed.getName())) && !(smsFltType.equals("1") && smsFltisFoue.equals("true") && fltLv.equals("4")))){
					LogUtil.info(this.getClass().getName(), "JOB--现行故障短信过滤，人员ID（"+UserID+"），人员名称（"+UserName+"），过滤的故障码（"+FaultCode+"）");
					continue;
				}
				
				//短信--故障发送类型（1：统一设置；2：单独设置）
				SMSAS_SMSFltSendType = MapGetter.getString(user, "SMSAS_SMSFltSendType");
				//开始时间
				SMSAS_SMSFltSendBegin = MapGetter.getString(user, "SMSAS_SMSFltSendBegin");
				SMSAS_SMSFltSendEnd = MapGetter.getString(user, "SMSAS_SMSFltSendEnd");
				
				SC_SendTime_Bgn = StringUtil.isValid(SMSAS_SMSFltSendBegin) ? SMSAS_SMSFltSendBegin + ":00" : ConfigEnum.SendTime_Bgn.getName();
				SC_SendTime_End = StringUtil.isValid(SMSAS_SMSFltSendEnd) ? SMSAS_SMSFltSendEnd + ":00" : ConfigEnum.SendTime_End.getName();
				//判断故障短信发送类型
				if(SMSAS_SMSFltSendType.equals("2")){
					smsSendTimeList.add(0, SC_SendTime_Bgn);
					smsSendTimeList.add(1, SC_SendTime_End);
				}
				
				// 判断在工作时间内，同一台车同一个故障在半个小时内是否发生过
				boolean isOccured = smsInfoDAO.assTimeIsOccuredFlt(smsSendTimeList, sqls[0]);
				if (isOccured) {
					LogUtil.info(this.getClass().getName(), "1.2.1JOB--现行故障短信是否发送成功："
							+ flag);
					continue;
				}
				
				// 过滤在非工作时间发送的重复信息
				isOccured = smsInfoDAO.nonWorkIsOccuredFlt(smsSendTimeList, sqls[1],
						MsgTime, sqls[0]);
				if (isOccured) {
					LogUtil.info(this.getClass().getName(), "1.2.1JOB--现行故障短信是否发送成功："
							+ flag);
					continue;
				}
				             
				// 获得设备所属机构Code值
				codeMap = this.getDBCode(VclID);
				// 获取设备组织机构
				DBCode = MapGetter.getString(codeMap, "DBCode");
				// 获得设备号
				VehicleNumber = MapGetter.getString(codeMap, "VehicleNumber");
				// 时间
				time = "";
				SMSContent = "";
				if(fltType.equals("1")){
					time = DateList.getFormatDate(MsgTime, 11);
					if(smsType.equals("1")){
						if(isSer == true){
							smsSendType = "1";
							SMSContent = SMSContentCfg.SMSCCfgFlt1.replace("X_VclNum", VehicleNumber).replace("X_ESNN",ESN).replace("X_Date", time).replace("X_Color",Color)
									.replace("X_FltCode", FaultCode).replace("X_FltMsgAbbr", FaultContenti).replaceAll("X_Risk", fltRisk)
									.replace("X_SerName", serName).replace("X_SerTel", serTel);
						}else{
							smsSendType = "1";
							SMSContent = SMSContentCfg.SMSCCfgFlt2.replace("X_VclNum", VehicleNumber).replace("X_ESNN",ESN).replace("X_Date", time).replace("X_Color",Color)
									.replace("X_FltCode", FaultCode).replace("X_FltMsgAbbr", FaultContenti).replaceAll("X_Risk", fltRisk)
									.replace("X_Factory", oem).replace("X_OEMTel", oemtel);
						}
					}else if(smsType.equals("2")){
						smsSendType = "17";
						SMSContent = SMSContentCfg.SMSCCfgFlt3.replace("X_VclNum", VehicleNumber).replace("X_ESNN",ESN).replace("X_Date", time).replace("X_Color",Color)
								.replace("X_FltCode", FaultCode).replace("X_FltMsgAbbr", FaultContenti).replaceAll("X_Risk", fltRisk)
								.replace("X_Position", Position).replace("X_SerName", VehicleContact).replace("X_SerTel", Tel);
					}else{
						//
					}
				}else if(fltType.equals("7")){
					if(smsType.equals("1"))
						smsSendType = "7";
					else
						smsSendType = "18";
					time = DateList.getFormatDate(MsgTime, 7);
					SMSContent = SMSContentCfg.SMSCCfgFltRels.replace("X_VclNum", VehicleNumber).replace("X_Date", time)
						.replace("X_FltCode", FaultCode);
				}else{
					return false;
				}
				SMSContent = this.deleteComma(SMSContent);
				
				// 发送短信条件及sql语句
				SMSMap = new HashMap<String, Object>();
				SMSMap.put("SMSCfgType", fltType);
				SMSMap.put("DBName", DBName);
				SMSMap.put("TabName", TableName);
				SMSMap.put("PromptType", fltType);
				SMSMap.put("CreateType", 1);
				SMSMap.put("SMSContent", SMSContent);
				SMSMap.put("DBCode", DBCode);
				SMSMap.put("MsgID", MsgID);
				SMSMap.put("MsgCID", MsgCID);
				SMSMap.put("SysISM_CodeColorInfo", SysISM_CodeColorInfo);
				SMSMap.put("fltLv", fltLv);
				
				// 发送短信 2013.03.29 haoyang注释,因释放:promptSMSInfo
				// 注:若发送,则需同步修改提示信息表中的短信接收人列
				boolean isSendU = smsInfoDAO.promptSMSInfoFlt(sqlList, paramList, SMSMap, user, smsSendTimeList,smsSendType);
				if(isSendU){
					UserNames += UserName+"，";
				}
			}
			
			// 更新故障报警-短信接收人
			if(StringUtil.isValid(UserNames)){
				updatePromptMsgUser(sqlList,paramList,fltType,hm,UserNames);
				flag = true;
			}
		}
		
//		flag = this.tranDAO.batch(sqlList, paramList);
		LogUtil.info(this.getClass().getName(), "1.2.1JOB--现行故障短信是否发送成功："
				+ flag);
		return flag;
	}
	/**
	 * 去除重复逗号，若最后一个字符为“,”也去除
	 * @param SMSContent
	 * @return
	 */
	private String deleteComma(String SMSContent) {
		SMSContent = SMSContent.replaceAll("，，", "，").replaceAll("，，", "，");
		if(SMSContent.lastIndexOf("，") == (SMSContent.length()-1))
			SMSContent = SMSContent.substring(0,SMSContent.length()-1);
		return SMSContent;
	}

	/**
	 * 执行SQL
	 * @param sqlList
	 * @param paramList
	 * @return
	 */
	public boolean tranSQLs(List<String> sqlList,List<Object[]> paramList){
		return this.tranDAO.batch(sqlList, paramList);
	}
	/**
	 * 更新故障信息所对应的位置
	 * @return
	 * @throws ParseException 
	 */
	public boolean updateFltPosition(String msgTime,String vehicleID) throws ParseException{
		boolean isOk = false;
		StringBuffer sql = new StringBuffer();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat sdfT = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
        String toDay = sdf.format(calendar.getTime());
        String toDayT = sdfT.format(calendar.getTime());
        
        calendar.add(Calendar.DATE, -1);    //得到前一天
        String yeDay = sdf.format(calendar.getTime());
        String yeDayT = sdfT.format(calendar.getTime());
		sql.append( "update Msg_Prompt set MsgP_La=case when msgu_la IS null then p.MsgP_La else msgu_la end," +
				"MsgP_Lo=case when msgu_lo IS null then p.MsgP_Lo else msgu_lo end " +
			"from Msg_Prompt m ");
	    if(sdfT.format(sdfT.parse(msgTime)).equals(toDayT)){
	    	  sql.append( "left join CTY_Egn_B.dbo.Msg_UDS_"+toDay+" on m.MsgP_MsgTime=MsgU_MsgTime and m.MsgP_VclID=MsgU_Vcl_ID and MsgU_SysTI_ID=6 " +
	    			  "left join CTY_Egn_B.dbo.Msg_PGN_"+toDay+" p  on m.MsgP_MsgTime=p.MsgP_MsgTime and m.MsgP_VclID=p.MsgP_Vcl_ID and MsgP_SysTI_ID=6 " +
	    			  "where (MsgU_La is not NULL and MsgU_Lo is not NULL) or (p.MsgP_La is not NULL and p.MsgP_Lo is not NULL) " +
	    			  "and (m.MsgP_La is NULL and m.MsgP_Lo is NULL) and m.MsgP_MsgTime>'"+toDayT+"' and m.MsgP_Type=1 " +
	    			  "and m.MsgP_MsgTime ='"+msgTime+"' and m.MsgP_VclID = '"+vehicleID+"' ");  
		}
	    if(sdfT.format(sdfT.parse(msgTime)).equals(yeDayT)){
	    	sql.append( "left join CTY_Egn_B.dbo.Msg_UDS_"+yeDay+" on m.MsgP_MsgTime=MsgU_MsgTime and m.MsgP_VclID=MsgU_Vcl_ID and MsgU_SysTI_ID=6 " +
	    			  "left join CTY_Egn_B.dbo.Msg_PGN_"+yeDay+" p  on m.MsgP_MsgTime=p.MsgP_MsgTime and m.MsgP_VclID=p.MsgP_Vcl_ID and MsgP_SysTI_ID=6 " +
	    			  "where (MsgU_La is not NULL and MsgU_Lo is not NULL) or (p.MsgP_La is not NULL and p.MsgP_Lo is not NULL) " +
	    			  "and (m.MsgP_La is NULL and m.MsgP_Lo is NULL) and m.MsgP_MsgTime>'"+yeDayT+"' and m.MsgP_Type=1 " +
	    			  "and m.MsgP_MsgTime ='"+msgTime+"' and m.MsgP_VclID = '"+vehicleID+"' ");  
	    }
		int i = this.baseDAO.execUpdate(
				sql.toString(),
				new Object[] {});
		if (i > 0){
			isOk = true;
		}
		return isOk;
	}
	/**
	 * 更新故障报警-短信接收人 SQL语句
	 * @param sqlList
	 * @param paramList
	 * @param fltType
	 * @param hm
	 * @param UserNames
	 */
	public void updatePromptMsgUser(List<String> sqlList,List<Object[]> paramList,String fltType,Map<String,Object> hm,String UserNames){
		if(fltType.equals("1")){
			sqlList.add("update Msg_Prompt set MsgP_SMSRecUser = ISNULL(MsgP_SMSRecUser,'，')+?"
					+ " where MsgP_Type =1 and MsgP_State = 1 "+ " and MsgP_VclId=? and MsgP_FltCode= ? " + " and MsgP_MsgTime = ?");
			paramList.add(new Object[] { UserNames,MapGetter.getString(hm, "VehicleID"),MapGetter.getString(hm, "FaultCode"),
				MapGetter.getString(hm, "MessageTime") });
		}else if(fltType.equals("7")){
			sqlList.add("update Msg_Prompt set MsgP_SMSRecUser = ISNULL(MsgP_SMSRecUser,'，')+?"
				+ " where MsgP_Type =1 and MsgP_State = 3 "
				+ " and MsgP_VclId=? and MsgP_FltCode= ? "
				+ " and MsgP_ReleaseTime>? and MsgP_MsgTime<MsgP_ReleaseTime");//添加过滤条件：报警时间 小于 解除时间
			paramList.add(new Object[] { UserNames,MapGetter.getString(hm, "VehicleID"),MapGetter.getString(hm, "FaultCode"),
				MapGetter.getString(hm, "LastRelsTime")});
		}
	}
	
	/**
	 * 判断故障是否发生过sql
	 * @param DBName
	 * @param TableName
	 * @param VclID
	 * @param FaultCode
	 * @return
	 */
	public String[] getIsOccured_SQL(String DBName,String TableName,String VclID,String FaultCode,String SSR_Type){
		String dbname = getDBName(DBName);
		String isOccured_SQL;
		String tipTimeColumnName;
		String fltType = "1".equals(SSR_Type)?" and (SSR_Type=1 or SSR_Type=17) ":" and SSR_Type=7 ";
		boolean flag = true;
		if (DBName.equals("A")
				|| (DBName.equals("B") && TableName.equals("Flt"))) {
			isOccured_SQL = "select count(*) as cnt from SMS_SendRecord as ssr "
					+ "inner join "
					+ dbname
					+ ".dbo.Msg_Flt_Content as mfc on mfc.MsgFCo_ID = ssr.SSR_MsgCID "
					+ "inner join "
					+ dbname
					+ ".dbo.Msg_Flt as mf on mf.MsgF_ID = mfc.MsgFCo_MsgF_ID and mf.MsgF_Vcl_ID="
					+ VclID
					+ " "
					+ "inner join CTY_Vcl.dbo.Sys_FltISM as fi on fi.SysISM_FMI=mfc.MsgFCo_FaultFMI   "
					+ "and fi.SysISM_SPN=mfc.MsgFCo_FaultSPN and fi.SysISM_Code='"
					//+ FaultCode + "' where 1=1 and SSR_Type = "+SSR_Type+" ";				3.6.9修改jinjiayu
					+ FaultCode + "' where 1=1 "+fltType;
			tipTimeColumnName = "mf.MsgF_MsgTime";
		} else if (DBName.equals("B") && TableName.equals("Flt_UDS")) {
			isOccured_SQL = "select count(*) as cnt from SMS_SendRecord as ssr "
					+ "inner join CTY_Egn_B.dbo.Msg_Flt_UDS_Content as mfc on mfc.MsgFUC_ID = ssr.SSR_MsgCID "
					+ "inner join CTY_Egn_B.dbo.Msg_Flt_UDS as mf on mf.MsgFU_ID = mfc.MsgFUC_MsgFU_ID and MsgFU_Vcl_ID="
					+ VclID
					+ "inner join CTY_Vcl.dbo.Sys_FltISM as fi on fi.SysISM_FMI=mfc.MsgFUC_FltFMI "
					+ "and fi.SysISM_SPN=mfc.MsgFUC_FltSPN and fi.SysISM_Code='"
					+ FaultCode + "' where 1=1  and SSR_Type = "+SSR_Type+" ";
			tipTimeColumnName = "mf.MsgFU_MsgTime";
		} else {
			isOccured_SQL = "";
			tipTimeColumnName = "";
			LogUtil.info(this.getClass().getName(), "1.2.1JOB--现行故障短信是否发送成功："
					+ flag);
			flag = false;
		}
		
		if(flag){
			return new String[]{isOccured_SQL,tipTimeColumnName};
		}else{
			return null;
		}
	}

	/**
	 * 判断同一台车同一个提示在半个小时内是否发生过
	 * 
	 * @param VehicleID
	 * @param isOccured
	 * @param MsgTimeName
	 * @param FaultTime
	 * @param type
	 * @return
	 */
	/********
	 * 说明：统一调用SMSInfoDAO类中的方法******************* public boolean isOccured(String
	 * VehicleID,String isOccured, String MsgTimeName,String FaultTime,int
	 * type,int SC_Type){ boolean flag = false;
	 * 
	 * String sql = "select * from SMS_Config where SC_Type=?";
	 * Map<String,Object> hm = this.baseDAO.execQueryOne(sql, new
	 * Object[]{SC_Type}); String nowTimeStr =
	 * DateUtil.toString(DateUtil.now()); String SC_SendTime_Bgn =
	 * hm.get("SC_SendTime_Bgn"
	 * )!=null?nowTimeStr.substring(0,10)+" "+hm.get("SC_SendTime_Bgn"
	 * ).toString()+":00":ConfigEnum.SendTime_Bgn.getName(); String
	 * SC_SendTime_End =
	 * hm.get("SC_SendTime_End")!=null?nowTimeStr.substring(0,10
	 * )+" "+hm.get("SC_SendTime_End"
	 * ).toString()+":00":ConfigEnum.SendTime_End.getName();
	 * 
	 * String sqls = ""; if(type==1){ String where =
	 * "where (ssr.SSR_CreateTime between DATEADD(mi,-30,GETDATE()) and GETDATE()) and "
	 * +"(convert(datetime,'"+nowTimeStr+"',120) between convert(datetime,'" +
	 * SC_SendTime_Bgn
	 * +"',120) and convert(datetime,'"+SC_SendTime_End+"',120))"; sqls =
	 * isOccured + where; }else if(type == 2){ String SC_SendTime_Bgn_Next =
	 * hm.get("SC_SendTime_Bgn")!=null?DateUtil.addDay(1)+" "+hm.get(
	 * "SC_SendTime_Bgn").toString()+":00":ConfigEnum.SendTime_Bgn.getName();
	 * String SC_SendTime_End_Up = hm.get("SC_SendTime_End") !=
	 * null?DateUtil.addDay
	 * (-1)+" "+hm.get("SC_SendTime_End").toString()+":00":ConfigEnum
	 * .SendTime_End.getName(); String where =
	 * " where ("+MsgTimeName+" between convert(datetime,'"
	 * +SC_SendTime_End+"',120) and convert(datetime,'"
	 * +SC_SendTime_Bgn_Next+"',120) and convert(datetime,'"
	 * +FaultTime+"',120)>convert(datetime,'"+SC_SendTime_End+"',120)) or "
	 * +"("+MsgTimeName+" between convert(datetime,'"+SC_SendTime_End_Up+
	 * "',120) and convert(datetime,'"
	 * +SC_SendTime_Bgn+"',120) and convert(datetime,'"
	 * +FaultTime+"',120)<convert(datetime,'"+SC_SendTime_Bgn+"',120))"; sqls =
	 * isOccured + where; } List<Map<String, Object>> list = new
	 * ArrayList<Map<String, Object>>(); list = this.baseDAO.execQuery(sqls, new
	 * Object[]{VehicleID}); if(list != null && list.size()>0){ flag = true; }
	 * return flag; }
	 ********************/

	/**
	 * 获得发送时间
	 */
	/********
	 * 说明：统一调用SMSInfoDAO类中的getTimingSendTime方法********* public String
	 * getTimingSendTime(String SC_Type){ String sendTime = ""; try{ String sql
	 * = "select * from SMS_Config where SC_Type=?"; Map<String,Object> hm =
	 * this.baseDAO.execQueryOne(sql, new Object[]{SC_Type}); String nowTimeStr
	 * = DateUtil.toString(DateUtil.now()); String SC_SendTime_Bgn =
	 * hm.get("SC_SendTime_Bgn"
	 * )!=null?hm.get("SC_SendTime_Bgn").toString()+":00"
	 * :ConfigEnum.SendTime_Bgn.getName(); String SC_SendTime_End =
	 * hm.get("SC_SendTime_End"
	 * )!=null?hm.get("SC_SendTime_End").toString()+":00"
	 * :ConfigEnum.SendTime_End.getName(); long nowTimel =
	 * DateUtil.now().getTime(); long beginl =
	 * DateUtil.toDate(DateUtil.toString(DateUtil.now(),
	 * "yyyy-MM-dd")+" "+SC_SendTime_Bgn, "yyyy-MM-dd HH:mm:ss").getTime(); long
	 * endl = DateUtil.toDate(DateUtil.toString(DateUtil.now(),
	 * "yyyy-MM-dd")+" "+SC_SendTime_End, "yyyy-MM-dd HH:mm:ss").getTime();
	 * //发送规则 if(beginl<=nowTimel&&nowTimel<=endl){ sendTime = nowTimeStr; }else
	 * if(beginl>nowTimel){ sendTime = DateUtil.toString(DateUtil.now(),
	 * "yyyy-MM-dd")+" "+SC_SendTime_Bgn; }else{ java.util.Calendar
	 * calendar=java.util.Calendar.getInstance();
	 * calendar.roll(java.util.Calendar.DAY_OF_YEAR,1); sendTime =
	 * DateUtil.toString(calendar.getTime(), "yyyy-MM-dd")+" "+SC_SendTime_Bgn;
	 * } }catch(Exception e){ e.printStackTrace(); } return sendTime; }
	 ***************/

	public boolean udpateAlarmInfoExp(String MtnA_ID) {
		String sql = "update Mtn_Alarm_Info set MtnA_Exp=GETDATE() where MtnA_ID=?";
		return baseDAO.execUpdate(sql, new Object[] { MtnA_ID }) > 0 ? true
				: false;
	}

	/**
	 * 获得设备所属机构的DBCode值
	 */
	public Map<String, Object> getDBCode(String VehicleID) {
		Map<String, Object> hm = null;
		try {
			String sql = "select vvi.DBCode," + "vvi.VehicleNumber "
					+ "from V_VehicleInfo as vvi where vvi.VehicleID=?";
			hm = this.baseDAO.execQueryOne(sql, new Object[] { VehicleID });
		} catch (Exception e) {
			e.printStackTrace();
		}
		return hm;
	}

	/**
	 * 查询机构下所有定制短信的人员
	 */
	public List<Map<String, Object>> getUserInfo(Map<String, Object> hm,
			String SMSType) {
		List<Map<String, Object>> list = null;
		try {
			String DBCode = hm.get("DBCode") != null ? hm.get("DBCode")
					.toString() : "";
			for (; list == null;) {
				list = getUserInfo(DBCode, SMSType);
				if (list != null)
					break;
				// 获得最后分隔符的索引
				int index = DBCode.lastIndexOf(ConfigEnum.orgCodeCompart
						.getName());
				// 如果得到的索引小于0（已经不存在分隔符），退出循环
				if (index < 0)
					break;
				// 获得父级Code值
				DBCode = DBCode.substring(0, index);
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 查询机构下所有定制短信的人员
	 */
	public List<Map<String, Object>> getUserInfo(String DBCode, String SMSType) {
		List<Map<String, Object>> list = null;
		try {
			String sql = "select ui.UserID,ui.UserName,ui.Mobile "
					+ "from SMS_Alarm_SetInfo as smsas "
					+ "Left Join UserInfo as ui ON smsas.SMSAS_UsP_ID=ui.UserID "
					+ "Left Join UserInfo_Organization as uio ON uio.UserID=ui.UserID "
					+ "Left Join Organization_DB as odb ON uio.OrganizationID=odb.OrganizationID "
					+ "where odb.OrganizationCode=? and smsas." + SMSType
					+ "=1";
			list = this.baseDAO.execQuery(sql, new Object[] { DBCode });
			if (list == null)
				return list;
			if (list.size() == 0)
				return null;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}


	/**
	 * 保养信息轮询——————————————————begin
	 */
	/**
	 * 获得保养提醒表中5分钟内的数据
	 */
	public List<Map<String, Object>> getMaintData(double istBgnMaxId,
			double istEndMaxId) {
		List<Map<String, Object>> list = null;
		try {
			list = new ArrayList<Map<String, Object>>();
			String sql = "select ui.VehicleID,"
					+ "mai.MtnA_AlarmHours,"
					+ "mai.MtnA_AlarmKm,"
					+ "mai.MtnA_ID,"
					+ "mai.MtnA_AlarmDays,"
					+ "(select SysMT_Type from Sys_MtnType where SysMT_ID=mfs.MtnFS_SysMT_ID)as SysMT_Type "
					+ "from Mtn_Alarm_Info as mai "
					+ "Left Join V_VehicleInfo as ui ON mai.MtnA_Vcl_ID=ui.VehicleID "
					+ "Left Join MtnForst_Standard as mfs ON mai.MtnA_MtnFS_ID=mfs.MtnFS_ID "
					+ "where mai.MtnA_Exp>GETDATE() "
					+
					// "and DATEDIFF(MINUTE,mai.MtnA_Eff,GETDATE())<=5 " +
					"and mai.MtnA_Eff<=GETDATE() "
					+ "and mai.MtnA_ID>? and mai.MtnA_ID<=?";
			list = baseDAO.execQuery(sql, new Object[] { istBgnMaxId,
					istEndMaxId });
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 发送保养信息入口 2013.04.09 haoyang 修改:将短信接收人作为参数传入
	 */
	public boolean sendMaintInfo(String SSR_MtnA_ID, String VehicleID,
			String SysMT_Type, String value, String contentType,
			List<Map<String, Object>> userList) {
		/*** IEMS 3.0 上线，屏蔽短信发送 ***********/
		Map<String, Object> codeMap = this.getDBCode(VehicleID); // 获得要发送的用户列表
		// List<Map<String, Object>> userList = this.getUserInfo(codeMap,
		// SMSType);
		boolean flag = false;
		// 获得发送时间——保养计划提醒短信为：2
		String sendTime = smsInfoDAO.getTimingSendTime("2"); 
		for (Map<String, Object> userMap : userList) {
			String sql = "";
			if(sendTime.toLowerCase().equals("null")){
				sql = "insert into SMS_SendRecord(SSR_MsgID,SSR_UsP_ID,SSR_UserName,SSR_Mobile,SSR_Content,SSR_CreateTime,SSR_Type,SSR_CreateType,SSR_MsgCID,SSR_DBName,SSR_TableName)values(?,?,?,?,?,GETDATE(),3,1,?,'M','');";
			} else{
				sql = "insert into SMS_SendRecord(SSR_MsgID,SSR_UsP_ID,SSR_UserName,SSR_Mobile,SSR_Content,SSR_CreateTime,SSR_Type,SSR_CreateType,SSR_MsgCID,SSR_DBName,SSR_TableName)values(?,?,?,?,?,"+sendTime+",3,1,?,'M','');";
			}
			
			//sql += "insert into SubTransQueue (OrderNumber,SourceNumber,MessageContent,TransportResult,TimingSendTime)values(?,?,?,?,"+sendTime+");"; // 获得设备号
			String VehicleNumber = codeMap.get("VehicleNumber") != null ? codeMap
					.get("VehicleNumber").toString() : ""; // 获得接收者姓名
			String UserName = userMap.get("UserName") != null ? userMap.get(
					"UserName").toString() : "";
			String Content = "";
			if (contentType.equals("1")) {
				Content = getSendContent_M(UserName, VehicleNumber, value,
						SysMT_Type);
			} else if (contentType.equals("2")){
				Content = getSendContent_MKm(UserName, VehicleNumber,
						value, SysMT_Type);
			} else if (contentType.equals("3")){
				/****LXF***2013-06-03***********/
				Content = getSendContent_MDays(UserName, VehicleNumber, value, SysMT_Type);
			}
			if (Content.length() > 60) {
				String _Content = Content.substring(0, 60);
				String Content_ = Content.substring(60);
				int i = this.baseDAO.execUpdate(
						sql,
						new Object[] { SSR_MtnA_ID, userMap.get("UserID"),
								userMap.get("UserName"), userMap.get("Mobile"),
								_Content, SSR_MtnA_ID,
								userMap.get("Mobile"),
								ConfigEnum.SourceNumber.getName(), _Content,
								"-1" });
				int j = this.baseDAO.execUpdate(
						sql,
						new Object[] { SSR_MtnA_ID, userMap.get("UserID"),
								userMap.get("UserName"), userMap.get("Mobile"),
								Content_, SSR_MtnA_ID,
								userMap.get("Mobile"),
								ConfigEnum.SourceNumber.getName(), Content_,
								"-1" });
				if (i > 0 && j > 0)
					flag = true;
			} else {
				int i = this.baseDAO.execUpdate(
						sql,
						new Object[] { SSR_MtnA_ID, userMap.get("UserID"),
								userMap.get("UserName"), userMap.get("Mobile"),
								Content, SSR_MtnA_ID,
								userMap.get("Mobile"),
								ConfigEnum.SourceNumber.getName(), Content,
								"-1" });
				if (i > 0)
					flag = true;
			}
			// haoyang 2013.04.09 add
			if (flag) {
				// 更新提示信息表中 相应的短信接收人
				String sql1 = "update Msg_Prompt set MsgP_SMSRecUser = ISNULL(MsgP_SMSRecUser,'，')+? "
						+ " where MsgP_MsgID=? and MsgP_MsgCID =? and MsgP_Type = 3 and MsgP_VclID = ? ";
				this.baseDAO.execUpdate(sql1, new Object[] { UserName+"，",
						SSR_MtnA_ID, SSR_MtnA_ID, VehicleID });
			}
		}
		return flag;
	}

	/**
	 * 发送保养信息内容
	 */
	public static String getSendContent_M(String UserName, String VehicleNumber,
			String hours, String SysMT_Type) {
		StringBuffer sb = new StringBuffer();
		sb.append("尊敬的" + UserName + "客户您好，您的" + VehicleNumber + "设备预计还有"
				+ hours + "工作小时后需要进行" + SysMT_Type + "级保养，请知晓！");
		return sb.toString();
	}

	public static String getSendContent_MKm(String UserName, String VehicleNumber,
			String km, String SysMT_Type) {
		StringBuffer sb = new StringBuffer();

		sb.append("尊敬的" + UserName + "客户您好，您的" + VehicleNumber + "设备预计还有" + km
				+ "公里后需要进行" + SysMT_Type + "级保养，请知晓！");

		return sb.toString();
	}
	
	public static String getSendContent_MDays(String UserName, String VehicleNumber,
			String day, String SysMT_Type) {
		StringBuffer sb = new StringBuffer();

		sb.append("尊敬的" + UserName + "客户您好，您的" + VehicleNumber + "设备预计还有" + day
				+ "天后需要进行" + SysMT_Type + "级保养，请知晓！");

		return sb.toString();
	}

	/**
	 * 获取某故障报告 相关信息功能 ，方法可进行修正
	 * 
	 * @param sqlList
	 * @param paramList
	 * @return
	 */
	public List<Map<String, Object>> getCalOverDue() {
		List<Map<String, Object>> rsList = new ArrayList<Map<String, Object>>();

		// 当前日期
		String sql = "  SELECT VAR_ID,VAR_VehicleNumber FROM VEH_AccountReceivable  where  VAR_ClaimState=0 ";

		try {
			rsList = this.getBaseDAO().execQuery(sql, new Object[] {});
		} catch (Exception ex) {
			System.out.print("MalfunctionDiagnosisDAO类的getCardType()方法有错误"
					+ ex.getMessage());
		}

		return rsList;
	}

	/**
	 * 保养信息轮询——————————————————end
	 */

	/**
	 * 保养预测信息轮询————————————————begin
	 */
	/**
	 * 加载预测信息
	 */
	public List<Map<String, Object>> initForstInfo(String MtnAlarmHours) {
		List<Map<String, Object>> list = null;
		try {
			String sql = "select mfi.MtnF_ID,mfi.MtnF_VclT_ID,"
					+ "mfi.MtnF_Vcl_ID,"
					+ "mtpl.MsgTL_tEWork,"
					+ "mfi.MtnF_MtnFS_ID,"
					+ "cast(MtnF_ForstWorkTime as float)-cast(mtpl.MsgTL_tEWork as float) as AlarmHours "
					+ "from MtnForst_Info as mfi "
					+ "Left Join CTY_Egn_A.dbo.Msg_Timing_Last as mtpl ON mfi.MtnF_Vcl_ID=mtpl.MsgTL_Vcl_ID "
					+ "where mfi.MtnF_ForstWorkTime<cast(mtpl.MsgTL_tEWork as float)+"
					+ MtnAlarmHours
					+ " and mfi.MtnF_ForstTime<=GETDATE() and mfi.MtnF_AlarmState=0;";
			list = this.baseDAO.execQuery(sql, new Object[] {});
		} catch (Exception e) {
			e.printStackTrace();
		}
		return list;
	}

	/**
	 * 从维保记录中提取要进行提醒的数据并插入保养提醒表中
	 * @param MtnAlarmHours
	 * @param MtnA_AlarmKm
	 * @param MtnAlarmDays	保养提前提示天数
	 */
	public void initMtnRepair_Info(float MtnAlarmHours, float MtnA_AlarmKm, int MtnAlarmDays) {
		String sfDayi = EquipVersionCommon.getSoftVerByAgrType("MRVcl_D");// 大一设备软件版本号，拼接成查询条件字符串（'CUMM3.3','CUMM3.3.1','CUMM3.3.2','CUMM3.3.3'）
		String sfJ = EquipVersionCommon.getSoftVerByAgrType("MRVcl_J");// 小一设备J，拼接成字符串（'CUMM3.4'）
		String sfPP = EquipVersionCommon.getSoftVerByAgrType("MRVcl_PP");// 小一设备PP，拼接成字符串（'CUMM3.5'）
		String sfJPP = EquipVersionCommon.getSoftVerByAgrType("MRVcl_JPP");;// 小一设备JPP，拼接成查查询条件字符串（'CUMM3.6'）
		
		//协议313
		StringBuffer sql313 = new StringBuffer();
		sql313.append("select VehicleRumKmID,tpp.* from (select Max(mri.MtnR_ID)as MtnR_ID,VehicleTypeID,VehicleID,ISNULL(mfs.MtnFS_MtnType,1) as MtnFS_MtnType, ");
		sql313.append("MtnHours=case when (select SysPC_MtnInHours from Sys_ParmConfig)>ISNULL(MAX(tmp.tEWorkHours),0) ");
		sql313.append("then(select ISNULL(MtnFS_MtnInHours,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		sql313.append("when (select SysPC_MtnInHours from Sys_ParmConfig)<ISNULL(MAX(tmp.tEWorkHours),0) ");
		sql313.append("then (select ISNULL(MtnFS_MtnOutHours,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) end,");
		sql313.append("MAX(mri.MtnR_WorkTime)as MtnR_WorkTime,");
		sql313.append("MtnKm=case when (select SysPC_MtnInKm from Sys_ParmConfig)>ISNULL(MAX(tmp.ETDistance),0) ");
		sql313.append("then(select ISNULL(MtnFS_MtnInKm,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		sql313.append("when (select SysPC_MtnInKm from Sys_ParmConfig)<ISNULL(MAX(tmp.ETDistance),0) ");
		sql313.append("then (select ISNULL(MtnFS_MtnOutKm,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) end,");
		sql313.append("MAX(mri.MtnR_RunKm)as MtnR_RunKm,MAX(tmp.tEWorkHours) tEWorkHours,MAX(tmp.ETDistance) ETDistance,mri.MtnR_MtnFS_ID, ");
		/****LXF  固定时间间隔            20130603       Begin******************/
		sql313.append("MAX(MtnR_CloseTime) MtnR_CloseTime, ");
		sql313.append("convert(int,getdate()-MAX(MtnR_CloseTime)) as GapDays,  ");
		sql313.append("MtnFS_MtnGapDays=(select ISNULL(MtnFS_MtnGapDays,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		/****LXF  固定时间间隔            20130603       Begin******************/
		sql313.append("from (");
		sql313.append("select VehicleID,VehicleTypeID,EnginFactoryID, ISNULL(mtpl.MsgTL_tEWork,0) tEWorkHours,");
		sql313.append("ETDistance=case  VehicleRumKmID when 1 then null when 2 then MsgTL_tRunKm when 3 then mtpl.MsgTL_tRunKm1 when 4 then MsgTL_tRunKmECU ");
		sql313.append("when 5 then VclPL_TMileage else null end,VehicleRumKmID ");
		sql313.append("from V_VehicleInfo ");
		sql313.append("left join CTY_Egn_A.dbo.Msg_Timing_Last mtpl on VehicleID=mtpl.MsgTL_Vcl_ID ");
		sql313.append("left join CTY_Vcl.dbo.Vcl_Pstn_Last on VclPL_Vcl_ID=VehicleID   ");
		sql313.append("where GETDATE() <UsefulLife and Tmnl_SoftEdition is not null and ltrim(rtrim(Tmnl_SoftEdition))!='' ");
		sql313.append("and Tmnl_SoftEdition in ("+sfDayi+") ");
		sql313.append(")tmp ");
		sql313.append("left Join MtnRepair_Info as mri ON VehicleID=mri.MtnR_Vcl_ID ");
		sql313.append("left Join MtnForst_Standard as mfs ON mfs.MtnFS_VclT_ID=VehicleTypeID ");
		sql313.append("where mri.MtnR_Eff<=GETDATE() and mri.MtnR_Exp>=GETDATE() and mri.MtnR_SysMRT_ID=2 and mri.MtnR_AlarmState=0 ");
		sql313.append("and mfs.MtnFS_ID=mri.MtnR_MtnFS_ID ");
		sql313.append("group by VehicleID,mri.MtnR_MtnFS_ID,VehicleTypeID,mfs.MtnFS_MtnType,EnginFactoryID)tpp left join V_VehicleInfo vt on tpp.vehicleid = vt.VehicleID");
		
		//协议403
		StringBuffer sql403 = new StringBuffer();
		sql403.append("select VehicleRumKmID,tpp.* from (select Max(mri.MtnR_ID)as MtnR_ID,VehicleTypeID,VehicleID,ISNULL(mfs.MtnFS_MtnType,1) as MtnFS_MtnType, ");
		sql403.append("MtnHours=case when (select SysPC_MtnInHours from Sys_ParmConfig)>ISNULL(MAX(tmp.tEWorkHours),0) ");
		sql403.append("then(select ISNULL(MtnFS_MtnInHours,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		sql403.append("when (select SysPC_MtnInHours from Sys_ParmConfig)<ISNULL(MAX(tmp.tEWorkHours),0) ");
		sql403.append("then (select ISNULL(MtnFS_MtnOutHours,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) end,");
		sql403.append("MAX(mri.MtnR_WorkTime)as MtnR_WorkTime,");
		sql403.append("MtnKm=case when (select SysPC_MtnInKm from Sys_ParmConfig)>ISNULL(MAX(tmp.ETDistance),0) ");
		sql403.append("then(select ISNULL(MtnFS_MtnInKm,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		sql403.append("when (select SysPC_MtnInKm from Sys_ParmConfig)<ISNULL(MAX(tmp.ETDistance),0) ");
		sql403.append("then (select ISNULL(MtnFS_MtnOutKm,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) end,");
		sql403.append("MAX(mri.MtnR_RunKm)as MtnR_RunKm,MAX(tmp.tEWorkHours) tEWorkHours,MAX(tmp.ETDistance) ETDistance,");
		sql403.append("mri.MtnR_MtnFS_ID, ");
		/****LXF  固定时间间隔            20130603       Begin******************/
		sql403.append("MAX(MtnR_CloseTime) MtnR_CloseTime, ");
		sql403.append("convert(int,getdate()-MAX(MtnR_CloseTime)) as GapDays,  ");
		sql403.append("MtnFS_MtnGapDays=(select ISNULL(MtnFS_MtnGapDays,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		/****LXF  固定时间间隔            20130603       Begin******************/
		sql403.append("from (");
		sql403.append("select VehicleID,VehicleTypeID,EnginFactoryID, ISNULL(t1.MsgCCoL_ParmValue,0) tEWorkHours,");
		sql403.append("ETDistance=case VehicleRumKmID when 1 then t2.MsgCCoL_ParmValue when 2 then MsgTL_tRunKmExact ");
		sql403.append("when 3 then MsgTL_tRunKm when 4 then MsgTL_tRunKmECU when 5 then VclPL_TMileage else t2.MsgCCoL_ParmValue end,VehicleRumKmID  from V_VehicleInfo ");
		sql403.append("left join CTY_Egn_B.dbo.Msg_CAN_Content_Last t1 on t1.MsgCCoL_Vcl_ID=VehicleID and t1.MsgCCoL_SysCP_ID=20 and t1.MsgCCoL_ParmValue is not null ");
		sql403.append("left join CTY_Egn_B.dbo.Msg_CAN_Content_Last t2 on t2.MsgCCoL_Vcl_ID=VehicleID and t2.MsgCCoL_SysCP_ID=53 and t2.MsgCCoL_ParmValue is not null ");
		sql403.append("left join CTY_Egn_B.dbo.Msg_Timing_Last on MsgTL_Vcl_ID=VehicleID ");
		sql403.append("left join CTY_Vcl.dbo.Vcl_Pstn_Last on VclPL_Vcl_ID=VehicleID  ");
		sql403.append("where GETDATE() <UsefulLife and Tmnl_SoftEdition is not null and ltrim(rtrim(Tmnl_SoftEdition))!='' ");
		sql403.append("and Tmnl_SoftEdition in ("+sfJ+") ");
		sql403.append(")tmp ");
		sql403.append("left Join MtnRepair_Info as mri ON VehicleID=mri.MtnR_Vcl_ID ");
		sql403.append("left Join MtnForst_Standard as mfs ON mfs.MtnFS_VclT_ID=VehicleTypeID ");
		sql403.append("where mri.MtnR_Eff<=GETDATE() and mri.MtnR_Exp>=GETDATE() and mri.MtnR_SysMRT_ID=2 and mri.MtnR_AlarmState=0 ");
		sql403.append("and mfs.MtnFS_ID=mri.MtnR_MtnFS_ID ");
		sql403.append("group by VehicleID,mri.MtnR_MtnFS_ID,VehicleTypeID,mfs.MtnFS_MtnType,EnginFactoryID)tpp left join V_VehicleInfo vt on tpp.vehicleid = vt.VehicleID");
		
		//协议412
		StringBuffer sql412 = new StringBuffer();
		sql412.append("select VehicleRumKmID,tpp.* from (select Max(mri.MtnR_ID)as MtnR_ID,VehicleTypeID,VehicleID,ISNULL(mfs.MtnFS_MtnType,1) as MtnFS_MtnType, ");
		sql412.append("MtnHours=case when (select SysPC_MtnInHours from Sys_ParmConfig)>ISNULL(MAX(tmp.tEWorkHours),0) ");
		sql412.append("then(select ISNULL(MtnFS_MtnInHours,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		sql412.append("when (select SysPC_MtnInHours from Sys_ParmConfig)<ISNULL(MAX(tmp.tEWorkHours),0) ");
		sql412.append("then (select ISNULL(MtnFS_MtnOutHours,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) end,");
		sql412.append("MAX(mri.MtnR_WorkTime)as MtnR_WorkTime,");
		sql412.append("MtnKm=case when (select SysPC_MtnInKm from Sys_ParmConfig)>ISNULL(MAX(tmp.ETDistance),0) ");
		sql412.append("then(select ISNULL(MtnFS_MtnInKm,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		sql412.append("when (select SysPC_MtnInKm from Sys_ParmConfig)<ISNULL(MAX(tmp.ETDistance),0) ");
		sql412.append("then (select ISNULL(MtnFS_MtnOutKm,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) end,");
		sql412.append("MAX(mri.MtnR_RunKm)as MtnR_RunKm,MAX(tmp.tEWorkHours) tEWorkHours,MAX(tmp.ETDistance) ETDistance,");
		sql412.append("mri.MtnR_MtnFS_ID, ");
		/****LXF  固定时间间隔            20130603       Begin******************/
		sql412.append("MAX(MtnR_CloseTime) MtnR_CloseTime, ");
		sql412.append("convert(int,getdate()-MAX(MtnR_CloseTime)) as GapDays,  ");
		sql412.append("MtnFS_MtnGapDays=(select ISNULL(MtnFS_MtnGapDays,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		/****LXF  固定时间间隔            20130603       Begin******************/
		sql412.append("from (");
		sql412.append("select VehicleID,VehicleTypeID,EnginFactoryID, ISNULL(MsgTL_tWorkTime_UDS,0) tEWorkHours,");
		sql412.append("ETDistance=case VehicleRumKmID when 1 then u1.MsgUCL_UDSValue when 2 then null ");
		sql412.append("when 3 then null when 4 then null when 5 then VclPL_TMileage else u1.MsgUCL_UDSValue end,VehicleRumKmID ");
		sql412.append("from V_VehicleInfo ");
		sql412.append("left join (select * from CTY_Egn_B.dbo.Msg_UDS_Last inner join CTY_Egn_B.dbo.Msg_UDS_Content_Last " +
				     "on MsgUL_ID = MsgUCL_MsgUL_ID and MsgUCL_UDSID = '3027') u1 on VehicleID = MsgUL_Vcl_ID ");
		sql412.append("left join CTY_Egn_B.dbo.Msg_Timing_Last on MsgTL_Vcl_ID=VehicleID ");
		sql412.append("left join CTY_Vcl.dbo.Vcl_Pstn_Last on VclPL_Vcl_ID=VehicleID  ");
		sql412.append("where GETDATE() <UsefulLife and Tmnl_SoftEdition is not null and ltrim(rtrim(Tmnl_SoftEdition))!='' ");
		sql412.append("and Tmnl_SoftEdition in ("+sfPP+") ");
		sql412.append(")tmp ");
		sql412.append("left Join MtnRepair_Info as mri ON VehicleID=mri.MtnR_Vcl_ID ");
		sql412.append("left Join MtnForst_Standard as mfs ON mfs.MtnFS_VclT_ID=VehicleTypeID ");
		sql412.append("where mri.MtnR_Eff<=GETDATE() and mri.MtnR_Exp>=GETDATE() and mri.MtnR_SysMRT_ID=2 and mri.MtnR_AlarmState=0 ");
		sql412.append("and mfs.MtnFS_ID=mri.MtnR_MtnFS_ID ");
		sql412.append("group by VehicleID,mri.MtnR_MtnFS_ID,VehicleTypeID,mfs.MtnFS_MtnType,EnginFactoryID)tpp left join V_VehicleInfo vt on tpp.vehicleid = vt.VehicleID");
		
		//协议414
		StringBuffer sql414 = new StringBuffer();
		sql414.append("select VehicleRumKmID,tpp.* from (select Max(mri.MtnR_ID)as MtnR_ID,VehicleTypeID,VehicleID,ISNULL(mfs.MtnFS_MtnType,1) as MtnFS_MtnType, ");
		sql414.append("MtnHours=case when (select SysPC_MtnInHours from Sys_ParmConfig)>ISNULL(MAX(tmp.tEWorkHours),0) ");
		sql414.append("then(select ISNULL(MtnFS_MtnInHours,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		sql414.append("when (select SysPC_MtnInHours from Sys_ParmConfig)<ISNULL(MAX(tmp.tEWorkHours),0) ");
		sql414.append("then (select ISNULL(MtnFS_MtnOutHours,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) end,");
		sql414.append("MAX(mri.MtnR_WorkTime)as MtnR_WorkTime,");
		sql414.append("MtnKm=case when (select SysPC_MtnInKm from Sys_ParmConfig)>ISNULL(MAX(tmp.ETDistance),0) ");
		sql414.append("then(select ISNULL(MtnFS_MtnInKm,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		sql414.append("when (select SysPC_MtnInKm from Sys_ParmConfig)<ISNULL(MAX(tmp.ETDistance),0) ");
		sql414.append("then (select ISNULL(MtnFS_MtnOutKm,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) end,");
		sql414.append("MAX(mri.MtnR_RunKm)as MtnR_RunKm,MAX(tmp.tEWorkHours) tEWorkHours,MAX(tmp.ETDistance) ETDistance,");
		sql414.append("mri.MtnR_MtnFS_ID, ");
		/****LXF  固定时间间隔            20130603       Begin******************/
		sql414.append("MAX(MtnR_CloseTime) MtnR_CloseTime, ");
		sql414.append("convert(int,getdate()-MAX(MtnR_CloseTime)) as GapDays,  ");
		sql414.append("MtnFS_MtnGapDays=(select ISNULL(MtnFS_MtnGapDays,0) from MtnForst_Standard where MtnFS_ID=mri.MtnR_MtnFS_ID) ");
		/****LXF  固定时间间隔            20130603       Begin******************/
		sql414.append("from (");
		sql414.append("select VehicleID,VehicleTypeID,EnginFactoryID, ISNULL(MsgTL_tWorkTime_UDS,0) tEWorkHours,");
		sql414.append("ETDistance=case VehicleRumKmID when 1 then (case when MsgTL_tRunKmExact_PGN is not null then MsgTL_tRunKmExact_PGN else MsgPCL_PGNValue end) ");
		sql414.append("when 2 then MsgTL_tRunKmExact when 3 then MsgTL_tRunKm when 4 then MsgTL_tRunKmECU when 5 then VclPL_TMileage " +
				"else (case when MsgTL_tRunKmExact_PGN is not null then MsgTL_tRunKmExact_PGN else MsgPCL_PGNValue end) end,VehicleRumKmID  from V_VehicleInfo ");
		sql414.append("left join (select * from CTY_Egn_B.dbo.Msg_PGN_Last inner join CTY_Egn_B.dbo.Msg_PGN_Content_Last " +
			     "on MsgPL_ID = MsgPCL_MsgPL_ID and MsgPCL_SysPIP_ID = 405) p1 on VehicleID = MsgPL_Vcl_ID ");
		sql414.append("left join CTY_Egn_B.dbo.Msg_Timing_Last on MsgTL_Vcl_ID=VehicleID ");
		sql414.append("left join CTY_Vcl.dbo.Vcl_Pstn_Last on VclPL_Vcl_ID= VehicleID  ");
		sql414.append("where GETDATE() <UsefulLife and Tmnl_SoftEdition is not null and ltrim(rtrim(Tmnl_SoftEdition))!='' ");
		sql414.append("and Tmnl_SoftEdition in ("+sfJPP+") ");
		sql414.append(")tmp ");
		sql414.append("left Join MtnRepair_Info as mri ON VehicleID=mri.MtnR_Vcl_ID ");
		sql414.append("left Join MtnForst_Standard as mfs ON mfs.MtnFS_VclT_ID=VehicleTypeID ");
		sql414.append("where mri.MtnR_Eff<=GETDATE() and mri.MtnR_Exp>=GETDATE() and mri.MtnR_SysMRT_ID=2 and mri.MtnR_AlarmState=0 ");
		sql414.append("and mfs.MtnFS_ID=mri.MtnR_MtnFS_ID ");
		sql414.append("group by VehicleID,mri.MtnR_MtnFS_ID,VehicleTypeID,mfs.MtnFS_MtnType,EnginFactoryID)tpp left join V_VehicleInfo vt on tpp.vehicleid = vt.VehicleID");
		
		try {
			List<Map<String,Object>> allList = new ArrayList<Map<String,Object>>();
			
			List<Map<String, Object>> list313 = this.baseDAO.execQuery(sql313.toString(), new Object[] {});
			allList.addAll(list313);
			List<Map<String, Object>> list403 = this.baseDAO.execQuery(sql403.toString(), new Object[] {});
			allList.addAll(list403);
			List<Map<String, Object>> list412 = this.baseDAO.execQuery(sql412.toString(), new Object[] {});
			allList.addAll(list412);
			List<Map<String, Object>> list414 = this.baseDAO.execQuery(sql414.toString(), new Object[] {});
			allList.addAll(list414);
			
			for (Map<String, Object> map : allList) {
				if ("1".equals(map.get("MtnFS_MtnType") != null ? map.get("MtnFS_MtnType").toString() : "1")) {
					//保养方式为工作小时数
					float MtnHours = 0;
					MtnHours = Float.valueOf(map.get("MtnHours") != null ? map
							.get("MtnHours").toString() : "0");
					float workTime = Float
							.valueOf(map.get("MtnR_WorkTime") != null ? map
									.get("MtnR_WorkTime").toString() : "0");
					float tEWorkHours = Float
							.valueOf(map.get("tEWorkHours") != null ? map.get(
									"tEWorkHours").toString() : "0");
					if (tEWorkHours + MtnAlarmHours >= workTime + MtnHours
							&& tEWorkHours < workTime + MtnHours) {
						map.put("MtnAlarmHours", MtnAlarmHours + "");
						this.addMtnAlarmInfo(map);
					}
				} else if ("2".equals(map.get("MtnFS_MtnType") != null ? map.get("MtnFS_MtnType").toString() : "2")){
					//保养方式为公里数
					float MtnKm = 0;
					MtnKm = Float.valueOf(map.get("MtnKm") != null ? map.get(
							"MtnKm").toString() : "0");
					float runKm = Float
							.valueOf(map.get("MtnR_RunKm") != null ? map.get(
									"MtnR_RunKm").toString() : "0");
					float tKm = Float
							.valueOf(map.get("ETDistance") != null ? map.get(
									"ETDistance").toString() : "0");
					if (tKm + MtnA_AlarmKm >= runKm + MtnKm
							&& tKm < runKm + MtnKm) {
						map.put("MtnA_AlarmKm", MtnA_AlarmKm + "");
						this.addMtnAlarmInfoKm(map);
					}
				} else if ("3".equals(map.get("MtnFS_MtnType") != null ? map.get("MtnFS_MtnType").toString() : "3")){
					/****LXF****2013-06-03*****ADD******Begin****************/
					//保养方式为固定时间间隔
					String MtnR_CloseTime = MapGetter.getString(map, "MtnR_CloseTime");	//【停机日期】即上次保养日期
					String MtnFS_MtnGapDays = MapGetter.getString(map, "MtnFS_MtnGapDays");	//保养间隔天数
					if(StringUtil.isValid(MtnFS_MtnGapDays)){
						int MtnGapDays = Integer.parseInt(MtnFS_MtnGapDays);
						SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
						Date date=new Date();
						String nowTime = formatter.format(date);
						String closeTime = DateControl.getFormatDate(MtnR_CloseTime,0);
						//【停机日期】加上（【保养间隔天数】-【保养提前提示天数】）
						String new_CloseTime = DateControl.getNewDate(closeTime, MtnGapDays-MtnAlarmDays);
						//【停机日期】加上【保养间隔天数】
						String new_CloseTime2 = DateControl.getNewDate(closeTime, MtnGapDays);
						if((DateControl.getDate_NowDate(new_CloseTime).equals("no")||nowTime.equals(new_CloseTime))&&
								(DateControl.getDate_NowDate(new_CloseTime2).equals("yes")||nowTime.equals(new_CloseTime))){
							//保养提醒时间隔天数
							int GapDays = Integer.parseInt(MapGetter.getString(map, "GapDays"));
							//距保养天数=【保养间隔天数】-保养提醒时间隔天数
							int AlarmDays = MtnGapDays-GapDays;
							map.put("AlarmDays", AlarmDays);
							map.put("MtnA_CloseTime", MtnR_CloseTime);
							this.addMtnAlarmInfoDays(map);	
						}
					}
					/****LXF****2013-06-03*****ADD******End****************/
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 获取保养提醒表最大ID
	 * 
	 * @return
	 */
	public double getMtnAlarmInfoMaxID() {
		String strSQL = "select top 1 MtnA_ID from Mtn_Alarm_Info order by MtnA_ID desc;";
		Map<String, Object> map = baseDAO.execQueryOne(strSQL, new Object[] {});
		double id = map.get("MtnA_ID") != null ? Double.parseDouble(map.get(
				"MtnA_ID").toString()) : 1;
		return id;
	}

	/**
	 * 保养预测信息轮询入口 向保养提醒表里插入数据
	 * 
	 * @param list
	 * @return
	 */
	public boolean addMtnAlarmInfo(Map<String, Object> hm) {
		String VehicleTypeID = MapGetter.getString(hm, "VehicleTypeID");
		String VehicleID = MapGetter.getString(hm, "VehicleID");
		String tEWorkHours = MapGetter.getString(hm, "tEWorkHours");// 提醒时 工作小时
		String MtnR_MtnFS_ID = MapGetter.getString(hm, "MtnR_MtnFS_ID");
		String MtnAlarmHours = MapGetter.getString(hm, "MtnAlarmHours");// 距保
																		// 工作小时
		boolean flag = true;
		try {
			String sql = "insert into Mtn_Alarm_Info"
					+ "(MtnA_VclT_ID,MtnA_Vcl_ID,MtnA_WorkTime,MtnA_AlarmTime,MtnA_MtnFS_ID,MtnA_AlarmHours,MtnA_Eff,MtnA_Exp)"
					+ "values"
					+ "(?,?,?,GETDATE(),?,?,GETDATE(),?);update MtnRepair_Info set MtnR_AlarmState=1 where MtnR_ID="
					+ hm.get("MtnR_ID")
					+ ";"
					+
					/*** 2012-12-10****LXF****向提示表中插入数据 **************/
					// "insert into Msg_Prompt(MsgP_VclID,MsgP_MsgID,MsgP_MsgCID,MsgP_MsgTime,MsgP_Type,MsgP_State,MsgP_DBName,MsgP_TableName,MsgP_UpdateTime,MsgP_CreateTime) "
					// +"values(?,IDENT_CURRENT('Mtn_Alarm_Info'),'',GETDATE(),3,0,'M','Mtn_Alarm_Info',GETDATE(),GETDATE());";
					// int i = this.baseDAO.execUpdate(sql, new
					// Object[]{VehicleTypeID,VehicleID,tEWorkHours,MtnR_MtnFS_ID,MtnAlarmHours,ConfigEnum.expTime.getName(),
					// VehicleID});
					/** 2013.03.27 haoyang 修改 begin */
					"insert into Msg_Prompt(MsgP_VclID,MsgP_MsgID,MsgP_MsgCID,MsgP_MsgTime,MsgP_Type,MsgP_State,MsgP_DBName,MsgP_TableName,MsgP_UpdateTime,MsgP_CreateTime,"
					+ "MsgP_DetailMsg,MsgP_SecTypeId,MsgP_SecTypeName) "
					+ "values(?,IDENT_CURRENT('Mtn_Alarm_Info'),IDENT_CURRENT('Mtn_Alarm_Info'),GETDATE(),3,?,'M','Mtn_Alarm_Info',GETDATE(),GETDATE(),?,?,?);";
			Map<String, Object> mtnMsg = getMtnMsg(MtnR_MtnFS_ID, tEWorkHours,
					MtnAlarmHours, "", "", "", "", ConfigEnum.expTime.getName());
			int i = this.baseDAO.execUpdate(
					sql,
					new Object[] {
							VehicleTypeID,
							VehicleID,
							tEWorkHours,
							MtnR_MtnFS_ID,
							MtnAlarmHours,
							ConfigEnum.expTime.getName(),
							VehicleID,
							StringUtil.isNullOrEmpty(MapGetter.getString(
									mtnMsg, "MsgP_State")) ? MapGetter
									.getString(mtnMsg, "MsgP_State") : "6",
							MapGetter.getString(mtnMsg, "MsgP_DetailMsg"),
							MapGetter.getString(mtnMsg, "MsgP_SecTypeId"),
							MapGetter.getString(mtnMsg, "MsgP_SecTypeName"), });
			/** end */
			if (i <= 0)
				flag = false;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}

	public boolean addMtnAlarmInfoKm(Map<String, Object> hm) {
		String VehicleTypeID = MapGetter.getString(hm, "VehicleTypeID");
		String VehicleID = MapGetter.getString(hm, "VehicleID");
		String ETDistance = MapGetter.getString(hm, "ETDistance");//
		String MtnR_MtnFS_ID = MapGetter.getString(hm, "MtnR_MtnFS_ID");
		String MtnA_AlarmKm = MapGetter.getString(hm, "MtnA_AlarmKm");
		String MtnA_RunKMID = MapGetter.getString(hm, "VehicleRumKmID");
		boolean flag = true;
		try {
			String sql = "insert into Mtn_Alarm_Info"
					+ "(MtnA_VclT_ID,MtnA_Vcl_ID,MtnA_RunKm,MtnA_AlarmTime,MtnA_MtnFS_ID,MtnA_AlarmKm,MtnA_Eff,MtnA_Exp,MtnA_RunKMID)"
					+ "values"
					+ "(?,?,?,GETDATE(),?,?,GETDATE(),?,?);update MtnRepair_Info set MtnR_AlarmState=1 where MtnR_ID="
					+ hm.get("MtnR_ID")
					+ ";"
					+
					// /*** 2012-12-10****LXF****向提示表中插入数据 **************/
					// "insert into Msg_Prompt(MsgP_VclID,MsgP_MsgID,MsgP_MsgCID,MsgP_MsgTime,MsgP_Type,MsgP_State,MsgP_DBName,MsgP_TableName,MsgP_CreateTime) "
					// +
					// "values(?,IDENT_CURRENT('Mtn_Alarm_Info'),-1,GETDATE(),3,0,'','',GETDATE());";
					// int i = this.baseDAO.execUpdate(sql, new Object[] {
					// VehicleTypeID,
					// VehicleID, ETDistance, MtnR_MtnFS_ID, MtnA_AlarmKm,
					// ConfigEnum.expTime.getName(), VehicleID });
					/** 2013.03.27 haoyang 修改 begin */
					"insert into Msg_Prompt(MsgP_VclID,MsgP_MsgID,MsgP_MsgCID,MsgP_MsgTime,MsgP_Type,MsgP_State,MsgP_DBName,MsgP_TableName,MsgP_CreateTime,"
					+ "MsgP_DetailMsg,MsgP_SecTypeId,MsgP_SecTypeName) "
					+ "values(?,IDENT_CURRENT('Mtn_Alarm_Info'),IDENT_CURRENT('Mtn_Alarm_Info'),GETDATE(),3,?,'','',GETDATE(),?,?,?);";
			Map<String, Object> mtnMsg = getMtnMsg(MtnR_MtnFS_ID, "", "",
					ETDistance, MtnA_AlarmKm, "", "", ConfigEnum.expTime.getName());
			int i = this.baseDAO.execUpdate(
					sql,
					new Object[] {
							VehicleTypeID,
							VehicleID,
							ETDistance,
							MtnR_MtnFS_ID,
							MtnA_AlarmKm,
							ConfigEnum.expTime.getName(),
							MtnA_RunKMID,
							VehicleID,
							StringUtil.isNullOrEmpty(MapGetter.getString(
									mtnMsg, "MsgP_State")) ? MapGetter
									.getString(mtnMsg, "MsgP_State") : "6",
							MapGetter.getString(mtnMsg, "MsgP_DetailMsg"),
							MapGetter.getString(mtnMsg, "MsgP_SecTypeId"),
							MapGetter.getString(mtnMsg, "MsgP_SecTypeName"), });
			/** end */
			if (i <= 0)
				flag = false;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}
	public boolean addMtnAlarmInfoDays(Map<String, Object> hm) {
		String VehicleTypeID = MapGetter.getString(hm, "VehicleTypeID");
		String VehicleID = MapGetter.getString(hm, "VehicleID");
		String GapDays = MapGetter.getString(hm, "GapDays");// 提醒时间隔天数
		String MtnR_MtnFS_ID = MapGetter.getString(hm, "MtnR_MtnFS_ID");
		String AlarmDays = MapGetter.getString(hm, "AlarmDays");	//距保养天数.
		String MtnA_CloseTime = MapGetter.getString(hm, "MtnA_CloseTime");	//上次保养时间
		
		boolean flag = true;
		try {
			String sql = "insert into Mtn_Alarm_Info"
					+ "(MtnA_VclT_ID,MtnA_Vcl_ID,MtnA_GapDays,MtnA_AlarmDays,MtnA_AlarmTime,MtnA_CloseTime,MtnA_MtnFS_ID,MtnA_Eff,MtnA_Exp)"
					+ "values"
					+ "(?,?,?,?,GETDATE(),?,?,GETDATE(),?);update MtnRepair_Info set MtnR_AlarmState=1 where MtnR_ID="
					+ hm.get("MtnR_ID")
					+ ";"
					+
					/*** 2012-12-10****LXF****向提示表中插入数据 **************/
					// "insert into Msg_Prompt(MsgP_VclID,MsgP_MsgID,MsgP_MsgCID,MsgP_MsgTime,MsgP_Type,MsgP_State,MsgP_DBName,MsgP_TableName,MsgP_UpdateTime,MsgP_CreateTime) "
					// +"values(?,IDENT_CURRENT('Mtn_Alarm_Info'),'',GETDATE(),3,0,'M','Mtn_Alarm_Info',GETDATE(),GETDATE());";
					// int i = this.baseDAO.execUpdate(sql, new
					// Object[]{VehicleTypeID,VehicleID,tEWorkHours,MtnR_MtnFS_ID,MtnAlarmHours,ConfigEnum.expTime.getName(),
					// VehicleID});
					/** 2013.03.27 haoyang 修改 begin */
					"insert into Msg_Prompt(MsgP_VclID,MsgP_MsgID,MsgP_MsgCID,MsgP_MsgTime,MsgP_Type,MsgP_State,MsgP_DBName,MsgP_TableName,MsgP_UpdateTime,MsgP_CreateTime,"
					+ "MsgP_DetailMsg,MsgP_SecTypeId,MsgP_SecTypeName) "
					+ "values(?,IDENT_CURRENT('Mtn_Alarm_Info'),IDENT_CURRENT('Mtn_Alarm_Info'),GETDATE(),3,?,'M','Mtn_Alarm_Info',GETDATE(),GETDATE(),?,?,?);";
			Map<String, Object> mtnMsg = getMtnMsg(MtnR_MtnFS_ID, "",
					"", "", "",GapDays,AlarmDays, ConfigEnum.expTime.getName());
			int i = this.baseDAO.execUpdate(
					sql,
					new Object[] {
							VehicleTypeID,
							VehicleID,
							GapDays,
							AlarmDays,
							MtnA_CloseTime,
							MtnR_MtnFS_ID,
							ConfigEnum.expTime.getName(),
							VehicleID,
							StringUtil.isNullOrEmpty(MapGetter.getString(
									mtnMsg, "MsgP_State")) ? MapGetter
									.getString(mtnMsg, "MsgP_State") : "6",
							MapGetter.getString(mtnMsg, "MsgP_DetailMsg"),
							MapGetter.getString(mtnMsg, "MsgP_SecTypeId"),
							MapGetter.getString(mtnMsg, "MsgP_SecTypeName"), });
			/** end */
			if (i <= 0)
				flag = false;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return flag;
	}

	/**
	 * 获取保养提前提醒时间和公里数
	 * 
	 * @return
	 */
	public Map<String, Object> getMtnAlarmHoursAndKm() {
		Map<String, Object> hm = new HashMap<String, Object>();
		try {
			String sql = "select SysPC_MtnAlarmHours,SysPC_MtnAlarmKm,SysPC_MtnAlarmDays from Sys_ParmConfig";
			hm = this.baseDAO.execQueryOne(sql, new Object[] {});
			// MtnAlarmHours =
			// hm.get("SysPC_MtnAlarmHours")!=null?hm.get("SysPC_MtnAlarmHours").toString():ConfigEnum.MtnAlarmHours.getName();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return hm;
	}

	/**
	 * 保养预测信息轮询————————————————end
	 */

	/**
	 * 日志DAO可自行设计 或调用 此方法
	 * 
	 * @param sqlList
	 * @param paramList
	 * @return
	 */
	public boolean addSynclog(List<String> sqlList, List<Object[]> paramList) {
		boolean flag = false;
		try {
			flag = this.getTranDAO().batch(sqlList, paramList);
		} catch (Exception ex) {
			System.out.print("MalfunctionDiagnosisDAO类的addSynclog()方法有错误"
					+ ex.getMessage());
		}
		return flag;
	}

	/**
	 * LXF 2012-12-07 判断提示信息是否存在
	 * 
	 * @param Type
	 * @param DBName
	 * @param TableName
	 * @param MsgCID
	 * @return
	 */
	public boolean isExist(int Type, String DBName, String TableName,
			String MsgCID) {
		boolean flag;
		if (getDBName(DBName).equals("")) {
			return false;
		}
		/***** 2012-12-07*****IEMS与TC合并*****LXF**********Begin ************/
		// String isExist =
		// "select * from Msg_Fault_State where MsgFS_MsgFC_ID=?";
		String isExist = "select * from Msg_Prompt where MsgP_Type=? and MsgP_DBName=? and MsgP_TableName=? and MsgP_MsgCID=?";
		/***** 2012-12-07*****IEMS与TC合并*****LXF**********Begin ************/
		List<Map<String, Object>> num = baseDAO.execQuery(isExist,
				new Object[] { Type, DBName, TableName, MsgCID });
		if (num != null && num.size() > 0) {
			flag = true;
		} else {
			flag = false;
		}
		return flag;
	}

	/**
	 * 获取数据库名称
	 * 
	 * @param DBName
	 * @return （A：CTY_Egn_A；B：CTY_Egn_B；V：CTY_Vcl；M：CTY_MS）
	 */
	public String getDBName(String DBName) {
		String dbname;
		if (DBName.equalsIgnoreCase("A")) {
			dbname = "CTY_Egn_A";
		} else if (DBName.equalsIgnoreCase("B")) {
			dbname = "CTY_Egn_B";
		} else if (DBName.equalsIgnoreCase("M")) {
			dbname = "CTY_MS";
		} else if (DBName.equalsIgnoreCase("V")) {
			dbname = "CTY_Vcl";
		} else {
			dbname = "";
		}
		return dbname;
	}

	/**
	 * 根据信息id,信息内容id 获取故障信息
	 * 
	 * @param DBName
	 * @param TableName
	 * @param MsgID
	 * @param MsgCID
	 * @return
	 */
	public Map<String, Object> getFaultMsg(String DBName, String TableName,
			Map<String, Object> hm) {
		String sql = "";
		//2013.05.09 haoyang 修改故障指示灯取值逻辑:1为on
		//FaultMLFCtionLamp 		故障指示灯
		//FaultRedStopLamp			红色停止灯
		//FaultAmberWarnLamp	琥珀色警告灯
		//FaultProtectLamp				保护灯
		/********改为直接从参数中获取*******By	LXF***********20130910*******Begin***********/
//		if ("A".equals(DBName)) {
//			sql = "select SysISM_Code as FltCode" +
//					",MsgFCo_FaultMLFCtionLamp as FaultMLFCtionLamp"+
//					",MsgFCo_FaultRedStopLamp as FaultRedStopLamp"+
//					",MsgFCo_FaultAmberWarnLamp as FaultAmberWarnLamp"+
//					",MsgFCo_FaultProtectLamp as FaultProtectLamp" +
//					",SysISM_ContentCN as FltMsg,SysISM_CodeColorInfo,SysISM_CodeColor"
//					+ " ,SysISM_ContentCN_Abbr as FltMsg_Abbr"
//					+ " from CTY_Egn_A.dbo.Msg_Flt mf"
//					+ " inner join CTY_Egn_A.dbo.Msg_Flt_Content mfc on MsgF_ID=MsgFCo_MsgF_ID and MsgF_Currently=0"
//					+ " inner join CTY_Vcl.dbo.Sys_FltISM ON MsgFCo_FaultSPN = SysISM_SPN AND MsgFCo_FaultFMI = SysISM_FMI"
//					+ " where mf.MsgF_ID = ? and mfc.MsgFCo_ID = ?";
//		} else if ("Flt".equals(TableName)) {
//			sql = "select SysISM_Code as FltCode" +
//					",MsgFCo_FaultMLFCtionLamp as FaultMLFCtionLamp"+
//					",MsgFCo_FaultRedStopLamp as FaultRedStopLamp"+
//					",MsgFCo_FaultAmberWarnLamp as FaultAmberWarnLamp"+
//					",MsgFCo_FaultProtectLamp as FaultProtectLamp"+
//					",SysISM_ContentCN as FltMsg,SysISM_CodeColorInfo,SysISM_CodeColor"
//					+ ",SysISM_ContentCN_Abbr as FltMsg_Abbr,mfc.MsgFCo_ID"
//					+ " from CTY_Egn_B.dbo.Msg_Flt mf"
//					+ " inner join CTY_Egn_B.dbo.Msg_Flt_Content mfc on MsgF_ID=MsgFCo_MsgF_ID and MsgFCo_FltType=0"
//					+ " inner join CTY_Vcl.dbo.Sys_FltISM ON MsgFCo_FaultSPN = SysISM_SPN AND MsgFCo_FaultFMI = SysISM_FMI"
//					+ " where mf.MsgF_ID = ? and mfc.MsgFCo_ID = ?";
//		} else {
//			sql = "select SysISM_Code as FltCode" +
//					",'' as FaultMLFCtionLamp" +
//					",'' as FaultRedStopLamp" +
//					",'' as FaultAmberWarnLamp" +
//					",'' as FaultProtectLamp" +
//					",SysISM_ContentCN as FltMsg,SysISM_CodeColorInfo,SysISM_CodeColor"
//					+ ",SysISM_ContentCN_Abbr as FltMsg_Abbr"
//					+ " from CTY_Egn_B.dbo.Msg_Flt_UDS mfu"
//					+ " inner join CTY_Egn_B.dbo.Msg_Flt_UDS_Content mfuc on MsgFU_ID=MsgFUC_MsgFU_ID and MsgFUC_FltType=0"
//					+ " inner join CTY_Vcl.dbo.Sys_FltISM ON MsgFUC_FltSPN = SysISM_SPN AND MsgFUC_FltFMI = SysISM_FMI"
//					+ " where mfu.MsgFU_ID = ? and mfuc.MsgFUC_ID = ?";
//		}
//		Map<String, Object> msgs = baseDAO.execQueryOne(sql, new Object[] {
//				MsgID, MsgCID });
//		if (msgs == null || msgs.size() == 0)
//			return null;
//		String fltCode = MapGetter.getString(msgs, "FltCode");// 故障代码
//		String FltContent = getLampString(msgs);// 指示灯状态
//		String FltMsg = MapGetter.getString(msgs, "FltMsg");// 故障信息
//		String SysISM_CodeColorInfo = MapGetter.getString(msgs,
//				"SysISM_CodeColorInfo");// 代码颜色 黄色...
//		String SysISM_CodeColor = MapGetter.getString(msgs, "SysISM_CodeColor");// 代码颜色
//																				// #XXXXXX
//		String FltMsg_Abbr = MapGetter.getString(msgs, "FltMsg_Abbr");// 故障缩写
		/********改为直接从参数中获取*******By	LXF***********20130910*******End***********/
		String fltCode = MapGetter.getString(hm, "FaultCode");// 故障代码
		String FltContent = getLampString(hm);// 指示灯状态
		String FltMsg = MapGetter.getString(hm, "FaultContenti");// 故障信息
		String SysISM_CodeColorInfo = MapGetter.getString(hm,
				"SysISM_CodeColorInfo");// 代码颜色 黄色...
		String SysISM_CodeColor = MapGetter.getString(hm, "FaultCodeColor");// 代码颜色
																				// #XXXXXX
		String FltMsg_Abbr = MapGetter.getString(hm, "FltISM_ContentCN_Abbr");// 故障缩写

		Map<String, Object> faultMsg = new HashMap<String, Object>();
		faultMsg.put("MsgP_FltCode", fltCode);// 故障代码
		faultMsg.put("MsgP_LampStatus", FltContent);// 指示灯
		faultMsg.put("MsgP_DetailMsg", SysISM_CodeColorInfo + "<br/>" + fltCode
				+ "<br/>" + FltContent + "<br/>" + FltMsg);// 详细信息
		faultMsg.put("MsgP_SecTypeId", SysISM_CodeColor);// 二级类别id
		faultMsg.put("MsgP_SecTypeName", SysISM_CodeColorInfo);// 二级类别名称
		faultMsg.put("MsgP_FltAbbr", FltMsg_Abbr);// 故障缩写
		return faultMsg;
	}
	//指示灯状态：如0021--off，off，未知，on
	private String getLampString(Map<String,Object> faultMsg){
		if(faultMsg==null||faultMsg.size()==0){
			return "2222";
		}
		String FaultMLFCtionLamp = MapGetter.getString(faultMsg, "FaultMLFCtionLamp");	//故障指示灯
		String FaultRedStopLamp = MapGetter.getString(faultMsg, "FaultRedStopLamp");//			红色停止灯
		String FaultAmberWarnLamp	= MapGetter.getString(faultMsg, "FaultAmberWarnLamp");//琥珀色警告灯
		String FaultProtectLamp = MapGetter.getString(faultMsg, "FaultProtectLamp");//				保护灯
		String lamp = 
				StringUtil.isNullOrEmpty(FaultMLFCtionLamp)?
						"0".equals(FaultMLFCtionLamp)?"0":"1".equals(FaultMLFCtionLamp)?"1":"2":"2";
		lamp += StringUtil.isNullOrEmpty(FaultRedStopLamp)?
				"0".equals(FaultRedStopLamp)?"0":"1".equals(FaultRedStopLamp)?"1":"2":"2";
		lamp += StringUtil.isNullOrEmpty(FaultAmberWarnLamp)?
				"0".equals(FaultAmberWarnLamp)?"0":"1".equals(FaultAmberWarnLamp)?"1":"2":"2";
		lamp += StringUtil.isNullOrEmpty(FaultProtectLamp)?
				"0".equals(FaultProtectLamp)?"0":"1".equals(FaultProtectLamp)?"1":"2":"2";
		return lamp;
	}

	/**
	 * 获取 保养预测信息
	 * 
	 * @param MtnFSID
	 *            保养标准id
	 * @param tEWorkHours
	 *            提醒时工作小时数
	 * @param MtnAlarmHours
	 *            距保工作小时
	 * @param MtnA_RunKm
	 *            提示时行驶公里数
	 * @param MtnA_AlarmKm
	 *            距保行驶公里数
	 * @param MtnGapDays		LXF  20130603  Add
	 *            提示时间隔天数
	 * @param AlarmDays			LXF  20130603  Add
	 * 			     距保养间隔天数
	 * @param expTime
	 *            失效时间
	 * @return
	 */
	public Map<String, Object> getMtnMsg(String MtnFSID, String tEWorkHours,
			String MtnAlarmHours, String MtnA_RunKm, String MtnA_AlarmKm,String MtnGapDays,String AlarmDays,
			String expTime) {
		Map<String, Object> mtnMsg = new HashMap<String, Object>();
		// 1.根据 MtnFSID 获得 保养标准级别和级别id
		String sql = "select SysMT_ID,SysMT_Type from MtnForst_Standard"
				+ " join Sys_MtnType smt on smt.SysMT_ID = MtnFS_SysMT_ID"
				+ " where MtnFS_ID= ?";
		Map<String, Object> mtnType = baseDAO.execQueryOne(sql,
				new Object[] { MtnFSID });
		// 2.拼接保养信息
		String detailMsg = MapGetter.getString(mtnType, "SysMT_Type") + "，"
				+ tEWorkHours + "，" + MtnA_RunKm + "，" + MtnAlarmHours + "，"
				+ MtnA_AlarmKm + "，" + MtnFSID+"，"+MtnGapDays+"，"+AlarmDays;
		mtnMsg.put("MsgP_DetailMsg", detailMsg);// 详细信息
		mtnMsg.put("MsgP_SecTypeId", MapGetter.getString(mtnType, "SysMT_ID"));// 二级类别id
		mtnMsg.put("MsgP_SecTypeName",
				MapGetter.getString(mtnType, "SysMT_Type"));// 二级类别名称
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date d;
		try {
			d = sdf.parse(expTime);
			mtnMsg.put("MsgP_State",
					System.currentTimeMillis() < d.getTime() ? "5" : "6");// 保养状态
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return mtnMsg;
	}

	/**
	 * 判断 提示列表中是否存在VclID,FltCode的未解除故障记录
	 * 
	 * @param VclId
	 * @param FltCode
	 * @return true:存在未解除故障信息,false:不存在未解除故障 2013.03.29 haoyang
	 */
	public boolean isExist(String VclId, String FltCode) {
		String sql = "select COUNT(1) as count from Msg_Prompt "
				+ " where MsgP_VclID = ?  and MsgP_FltCode=?  and MsgP_Type = 1 and MsgP_State<>'3' ";
		Map<String, Object> result = baseDAO.execQueryOne(sql, new Object[] {
				VclId, FltCode });
		String rlt = MapGetter.getString(result, "count");
		int num = 0;
		if (StringUtil.isNullOrEmpty(rlt)) {
			num = Integer.parseInt(rlt);
		}
		if (num > 0)
			return true;
		return false;
	}

	/**
	 * 发送故障解除短信
	 * 
	 * @param param
	 * @return 2013.04.08 haoyang 修改,将更新短信接收人,加入
	 */
	public boolean sendReleaseFltMsg(Map<String, Object> hm,
			List<Map<String, Object>> userList) {
		// 1 判断间隔时间段内是否发送
		String VclID = MapGetter.getString(hm, "VehicleID");
		String MsgID = MapGetter.getString(hm, "MessageID");
		String MsgCID = MapGetter.getString(hm, "MFC_MessageID");
		String MsgTime = MapGetter.getString(hm, "MessageTime");
		String DBName = MapGetter.getString(hm, "MsgFS_DBName");
		String TableName = MapGetter.getString(hm, "TableName");
		String FaultCode = MapGetter.getString(hm, "FaultCode");

		boolean flag = false;
		String isExist = "select * from SMS_SendRecord where SSR_MsgFC_ID=? and SSR_CreateType=? and SSR_DBName=?";
		List<Map<String, Object>> num = baseDAO.execQuery(isExist,
				new Object[] { MsgCID, "1", DBName });
		if (num != null && num.size() > 0) {
			LogUtil.info(this.getClass().getName(), "1.2.1JOB--故障解除短信是否发送成功："
					+ flag);
			return flag;
		}
		// 获取工作时间的时间段
		String[] sqls = getIsOccured_SQL(DBName, TableName, VclID, FaultCode,"7");
		String isOccured_SQL;
		String tipTimeColumnName;
		if(sqls == null ){
			return flag;
		}else{
			isOccured_SQL = sqls[0];
			tipTimeColumnName = sqls[1];
		}

		// 判断在工作时间内，同一台车同一个故障在半个小时内是解除过
		boolean isOccured = smsInfoDAO.assTimeIsOccured("7", isOccured_SQL);
		if (isOccured) {
			LogUtil.info(this.getClass().getName(), "1.2.1JOB--故障解除短信是否发送成功："
					+ flag);
			return flag;
		}

		// 过滤在非工作时间发送的重复信息
		isOccured = smsInfoDAO.nonWorkIsOccured("7", tipTimeColumnName,
				MsgTime, isOccured_SQL);
		if (isOccured) {
			LogUtil.info(this.getClass().getName(), "1.2.1JOB--故障解除短信是否发送成功："
					+ flag);
			return flag;
		}
		// 获得设备所属机构Code值
		Map<String, Object> codeMap = this.getDBCode(VclID);
		// 获取设备组织机构
		String DBCode = MapGetter.getString(codeMap, "DBCode");
		// 获得设备号
		String VehicleNumber = MapGetter.getString(codeMap, "VehicleNumber");
		// 时间
		String time = DateList.getFormatDate(MsgTime, 7);// 月,日,时

		String SMSContent = SMSContentCfg.SMSCCfgFltRels
				.replace("X_VclNum", VehicleNumber).replace("X_Date", time)
				.replace("X_FltCode", FaultCode);

		// 发送短信条件及sql语句
		List<String> sqlList = new ArrayList<String>();
		List<Object[]> paramList = new ArrayList<Object[]>();
		Map<String, Object> SMSMap = new HashMap<String, Object>();
		SMSMap.put("SMSType", "SMSAS_SMSRels");
		SMSMap.put("SMSCfgType", 7);
		SMSMap.put("DBName", DBName);
		SMSMap.put("TabName", TableName);
		SMSMap.put("PromptType", 7);
		SMSMap.put("CreateType", 1);
		SMSMap.put("SMSContent", SMSContent);
		SMSMap.put("DBCode", DBCode);
		SMSMap.put("MsgID", MsgID);
		SMSMap.put("MsgCID", MsgCID);

		// 发送短信
		smsInfoDAO.promptSMSInfo(sqlList, paramList, SMSMap, userList);
		// 2013.04.08 更新短信接收人
		add_UpdateSMSRecUsersSql(sqlList, paramList, hm, userList, "fltRels");
		flag = this.tranDAO.batch(sqlList, paramList);
		LogUtil.info(this.getClass().getName(), "1.2.1JOB--故障解除短信是否发送成功："
				+ flag);
		return flag;

	}

	// /**
	// * 故障解除,更新 短信接收人
	// * 不使用
	// * @param hm
	// * @return 2013.04.08 haoyang 修改:将短信接收人作为参数传入
	// */
	// public boolean updateFltRelsSMSRecUser(Map<String, Object> hm,
	// List<Map<String, Object>> users) {
	// String VclId = MapGetter.getString(hm, "VehicleID");
	// // 获得设备所属机构Code值
	// Map<String, Object> codeMap = this.getDBCode(VclId);
	// // 获取设备组织机构
	// String DBCode = MapGetter.getString(codeMap, "DBCode");
	// // //1.获取短信发送人员
	// // List<Map<String,Object>> users = smsInfoDAO.getSMSUsers(DBCode,
	// // "SMSAS_SMSRels");
	// String recUser = "";
	// for (Map<String, Object> map : users) {
	// if (StringUtil.isNullOrEmpty(MapGetter.getString(map, "UserName")))
	// recUser += MapGetter.getString(map, "UserName") + "，";
	// }
	// // 2.更新自上次 解除以来 的所有记录的短信接收人
	// String sql =
	// "update Msg_Prompt set MsgP_SMSRecUser = ISNULL(MsgP_SMSRecUser,'，')+?"
	// + " where MsgP_Type =1 and MsgP_State = 3 "
	// + " and MsgP_VclId=? and MsgP_FltCode= ? "
	// + " and MsgP_ReleaseTime>?";
	// int num = baseDAO.execUpdate(
	// sql,
	// new Object[] { recUser, VclId,
	// MapGetter.getString(hm, "FaultCode"),
	// MapGetter.getString(hm, "LastRelsTime") });
	// if (num > 0)
	// return true;
	// return false;
	// }

	/**
	 * 获取 X设备,Y故障 上次解除的时间
	 * 
	 * @param hm
	 *            :VehicleID,FaultCode 两个属性
	 * @return
	 */
	public String getLastRelsTime(Map<String, Object> hm) {
		String sql = "select max(Msgp_releaseTime) as MsgP_ReleaseTime "
				+ " from Msg_Prompt mp "
				//+ " join SMS_SendRecord ssr "
				//+ " on SSR_MsgCID = mp.MsgP_RelsCID "
				//+ " and SSR_DBName = mp.MsgP_DBName "
				//+ " and SSR_TableName = mp.MsgP_TableName "
				+ " where MsgP_VclID = ? and MsgP_FltCode = ? ";
		Map<String, Object> rlt = baseDAO.execQueryOne(
				sql,
				new Object[] { MapGetter.getString(hm, "VehicleID"),
						MapGetter.getString(hm, "FaultCode") });
		String relsTime = MapGetter.getString(rlt, "MsgP_ReleaseTime");
		if (StringUtil.isNullOrEmpty(relsTime)) {
			return relsTime;
		} else {
			return "1900-01-01";
		}
	}

	/**
	 * 添加 更新短信接收人 sql,及参数
	 * 
	 * @param sqlList
	 * @param params
	 * @param hm
	 * @param userList
	 *            type: 故障报警:fltAlarm,故障解除:fltRels,报警:alarm
	 */
	public void add_UpdateSMSRecUsersSql(List<String> sqlList,
			List<Object[]> params, Map<String, Object> hm,
			List<Map<String, Object>> userList, String type) {
		// 拼接短信接收人
		String recUser = smsInfoDAO.getSMSUsers(userList);

		String sql = "";
		Object[] param = new Object[] {};
		if ("fltAlarm".equals(type)) {
			sql = "update Msg_Prompt set MsgP_SMSRecUser = ISNULL(MsgP_SMSRecUser,'，')+?"
					+ " where MsgP_Type =1 and MsgP_State = 1 "
					+ " and MsgP_VclId=? and MsgP_FltCode= ? "
					+ " and MsgP_MsgTime = ?";
			param = new Object[] { recUser,
					MapGetter.getString(hm, "VehicleID"),
					MapGetter.getString(hm, "FaultCode"),
					MapGetter.getString(hm, "MessageTime") };
		} else if ("fltRels".equals(type)) {
			sql = "update Msg_Prompt set MsgP_SMSRecUser = ISNULL(MsgP_SMSRecUser,'，')+?"
					+ " where MsgP_Type =1 and MsgP_State = 3 "
					+ " and MsgP_VclId=? and MsgP_FltCode= ? "
					+ " and MsgP_ReleaseTime>? and MsgP_MsgTime<MsgP_ReleaseTime";//添加过滤条件：报警时间 小于 解除时间
			param = new Object[] { recUser,
					MapGetter.getString(hm, "VehicleID"),
					MapGetter.getString(hm, "FaultCode"),
					MapGetter.getString(hm, "LastRelsTime")};
		} else if ("alarm".equals(type)) {
			sql = "update Msg_Prompt set MsgP_SMSRecUser = ISNULL(MsgP_SMSRecUser,'，')+?"
					+ " where MsgP_Type =2 and MsgP_State = 1 "
					+ " and MsgP_VclId=? and MsgP_MsgID= ? and MsgP_MsgCID=? and MsgP_DBName=? and MsgP_TableName=? "
					+ " and MsgP_MsgTime = ?";
			param = new Object[] { recUser,
					MapGetter.getString(hm, "MsgAlm_Vcl_ID"),
					MapGetter.getString(hm, "MsgAlm_ID"),
					MapGetter.getString(hm, "MsgAlmC_ID"),
					MapGetter.getString(hm, "DBName"),
					MapGetter.getString(hm, "TableName"),
//					MapGetter.getString(hm, "MsgAlm_RcvTime") 20130705修改为信息发出时间MsgAlm_MsgTime
					MapGetter.getString(hm, "MsgAlm_MsgTime")
					};
		}
		if (StringUtil.isNullOrEmpty(recUser)) {
			sqlList.add(sql);
			params.add(param);
		}
	}
	/**
	 * 获取 提示表中 vclId_fltCode_fltTimes 信息
	 * @return
	 */
	public Map<String,String> getFltTimesFromMsgP(){
	/*	String sql = "select cast(mp.MsgP_VclID as varchar)+'_'+mp.MsgP_FltCode as vclId_fltCode "
				+",reverse(substring(reverse(Msgp_detailMsg),0,charindex('>',reverse(Msgp_detailMsg)))) as fltTimes " 
				+" from msg_prompt mp "
				+" join "
				+" (select  max(MsgP_MsgTime) as msgp_msgtime,MsgP_VclID,MsgP_FltCode "
				+" from Msg_Prompt " 
				+" where MsgP_Type=1 and MsgP_DetailMsg is not null and msgP_State=1 "
				+" group by MsgP_VclID,MsgP_FltCode) temp1 "
				+" on temp1.msgp_msgtime = mp.MsgP_MsgTime and temp1.MsgP_VclID = mp.MsgP_VclID "	
				+" and temp1.MsgP_FltCode = mp.MsgP_FltCode";*/
		/*String sql="select  mp.MsgP_VclID as vehicleid,mp.MsgP_FltCode as fltcode  "+
				",Msgp_detailMsg    "+
				"from msg_prompt mp  "+
				"join  "+
				"(select  max(MsgP_MsgTime) as msgp_msgtime,MsgP_VclID,MsgP_FltCode  "+
				"from Msg_Prompt   "+
				"where MsgP_Type=1 and MsgP_DetailMsg is not null and msgP_State=1  "+
				"group by MsgP_VclID,MsgP_FltCode) temp1  "+
				"on temp1.msgp_msgtime = mp.MsgP_MsgTime and temp1.MsgP_VclID = mp.MsgP_VclID  	"+
				"and temp1.MsgP_FltCode = mp.MsgP_FltCode "+
				"where MsgP_Type=1 and msgP_State=1 ";*/
		
		/*String sql="select mfh.MsgFH_Vcl_ID as vehicleid,"+
				" mfh.MsgFH_FltCount as fltTimes,"+
				" sf.SysISM_Code as fltcode "+
				" from  cty_vcl.dbo.sys_fltism  sf "+
				" inner join  Msg_Flt_HappeningLast mfhl "+
				" on 1=1 where sf.SysISM_SPN=mfhl.MsgFH_FaultSPN "+
				" and sf.SysISM_FMI=mfhl.MsgFH_FaultFMI ";*/
		String sql=" select msgfh_vcl_id as vehicleid,"+
				 	"msgfh_fltcount as fltTimes,"+
				" msgfh_faultspn as spn,"+
				" msgfh_faultfmi as fmi"+
				" from  Msg_Flt_HappeningLast  ";
		List<Map<String, Object>> rlt = baseDAO.execQuery(
				sql,
				new Object[] {});
		Map<String,String> retMap = new HashMap<String, String>(rlt.size());
		for (Map<String, Object> map:rlt) {
			//String[] flttimes=MapGetter.getString(map, "Msgp_detailMsg").split(">");
			retMap.put(MapGetter.getString(map, "vehicleid")+"_"+MapGetter.getString(map, "spn")+"_"+MapGetter.getString(map, "fmi"),MapGetter.getString(map, "fltTimes"));
		}
		return retMap;
	}
	
	public List<Map<String, Object>> getFaultDataAB(Map<String, String> map) {
		List<Map<String,Object>> listA = null;
		List<Map<String,Object>> listB = null;
		try{
			//0.查询 A，B库故障统计 标记位
			String sql = "select fltMR_MsgF_ID as MsgF_ID,fltMR_DBName from fltMsgRecord where fltMR_TableName='Flt'";
			List<Map<String,Object>> listID = baseDAO.execQuery(sql, new Object[]{});
			//1.获取 故障信息
			listA = new ArrayList<Map<String,Object>>();
			listB = new ArrayList<Map<String,Object>>();
			String sql_A = "select bm.MessageID,bm.FaultCodeColor,bm.FaultCode,bm.VehicleID,bm.FaultTypeID,bm.MessageTime,"   			
						+" bm.fi_FaultContent as FaultContenti,MsgFS_DBName,TableName,MFC_MessageID,FltISM_ContentCN_Abbr,LEFT(bm.mfl_FaultContent, 2) AS LampStatus,MsgF_RcvTime "
						+" ,fltTimes ,cast(bm.VehicleID as varchar)+'_'+bm.FaultCode as vclId_fltCode,SysISM_CodeColorInfo, "
						+"MsgFCo_FaultMLFCtionLamp FaultMLFCtionLamp,MsgFCo_FaultRedStopLamp as FaultRedStopLamp,MsgFCo_FaultAmberWarnLamp as FaultAmberWarnLamp, "
						+"MsgFCo_FaultProtectLamp as FaultProtectLamp,isnull(bm.MsgF_Lo,0.0) MsgF_Lo,isnull(bm.MsgF_La,0.0) MsgF_La,v.ESNNumber,isnull(v.VehicleContact,'') VehicleContact,isnull(v.VehicleChargedMobile,'') VehicleChargedMobile,'暂无位置' as Position "
						+",SysISM_Level,SysISM_Risk,OEMTel,OEMName,  SysISM_SPN,SysISM_FMI "
						+" from ( " 		
						+"(select mfl.MsgF_Vcl_ID as VehicleID,mfl.MsgF_ID as MessageID, mfl.MsgF_Lo,mfl.MsgF_La,"     		
						+" mfl.MsgF_MsgTime as MessageTime, fi.SysISM_Code as FaultCode,fi.SysISM_CodeColor as FaultCodeColor," 		
						+" fi.SysISM_ContentCN as fi_FaultContent ,CONVERT (smallint, mfl.MsgF_Currently) as FaultTypeID,mfl.MsgF_RcvTime as ReceivedTime,'A' as MsgFS_DBName,MsgFCo_ID as MFC_MessageID," 		
						+" fi.SysISM_ContentCN_Abbr as FltISM_ContentCN_Abbr,MsgF_FaultContent as mfl_FaultContent,'Flt' as TableName,MsgF_RcvTime "  		
						+",mfco.MsgFCo_ItemCount as fltTimes,SysISM_CodeColorInfo,fi.SysISM_Level,fi.SysISM_Risk " 
						+",MsgFCo_FaultMLFCtionLamp,MsgFCo_FaultRedStopLamp,MsgFCo_FaultAmberWarnLamp,MsgFCo_FaultProtectLamp,fi.SysISM_SPN,fi.SysISM_FMI  "
						+" from CTY_Egn_A.dbo.Msg_Flt as mfl " 		
						+" INNER JOIN CTY_Egn_A.dbo.Msg_Flt_Content mfco ON mfl.MsgF_ID = MsgFCo_MsgF_ID " 		
						+" INNER JOIN CTY_Vcl.dbo.Sys_FltISM as fi ON MsgFCo_FaultSPN = fi.SysISM_SPN AND MsgFCo_FaultFMI = fi.SysISM_FMI )	" 		
						+") bm inner join V_VehicleInfo v on v.VehicleID=bm.VehicleID " 		
						+" where bm.MessageID> ? "		
						+" order by bm.MessageTime ";
			String sql_B ="select bm.MessageID,bm.FaultCodeColor,bm.FaultCode,bm.VehicleID,bm.FaultTypeID,bm.MessageTime,"   		
						+" bm.fi_FaultContent as FaultContenti,MsgFS_DBName,TableName,MFC_MessageID,FltISM_ContentCN_Abbr,LEFT(bm.mfl_FaultContent, 2) AS LampStatus,MsgF_RcvTime " 	
						+",fltTimes,cast(bm.VehicleID as varchar)+'_'+bm.FaultCode as vclId_fltCode,SysISM_CodeColorInfo, "
						+"MsgFCo_FaultMLFCtionLamp FaultMLFCtionLamp,MsgFCo_FaultRedStopLamp as FaultRedStopLamp,MsgFCo_FaultAmberWarnLamp as FaultAmberWarnLamp, "
						+"MsgFCo_FaultProtectLamp as FaultProtectLamp,MsgF_Lo,MsgF_La,v.ESNNumber,isnull(v.VehicleContact,'') VehicleContact,isnull(v.VehicleChargedMobile,'') VehicleChargedMobile,'暂无位置' as Position "
						+",SysISM_Level,SysISM_Risk,OEMTel,OEMName ,SysISM_SPN,SysISM_FMI "
						+" from ( " 	
						+" (select mf.MsgF_Vcl_ID as VehicleID,mf.MsgF_ID as MessageID,null as MsgF_Lo,null as MsgF_La "	
						+" ,mf.MsgF_MsgTime as MessageTime,fi.SysISM_Code as FaultCode,fi.SysISM_CodeColor as FaultCodeColor, "  	
						+" fi.SysISM_ContentCN as fi_FaultContent,mfc.MsgFCo_FltType as FaultTypeID,mf.MsgF_RcvTime as ReceivedTime,'B' as MsgFS_DBName, mfc.MsgFCo_ID as MFC_MessageID, "     	
						+" fi.SysISM_ContentCN_Abbr as FltISM_ContentCN_Abbr,MsgFCo_FltValue as mfl_FaultContent,'Flt' as TableName,MsgF_RcvTime " 	
						+",mfc.msgFCo_FltCount as fltTimes,SysISM_CodeColorInfo "
						+",MsgFCo_FaultMLFCtionLamp,MsgFCo_FaultRedStopLamp,MsgFCo_FaultAmberWarnLamp,MsgFCo_FaultProtectLamp "
						+",fi.SysISM_Level,fi.SysISM_Risk ,fi.SysISM_SPN,fi.SysISM_FMI "
						//+",'--' as fltTimes  "//临时测试用
						+" from [CTY_Egn_B].[dbo].Msg_Flt as mf " 	
						+" INNER JOIN [CTY_Egn_B].[dbo].Msg_Flt_Content as mfc on mf.MsgF_ID = mfc.MsgFCo_MsgF_ID " 	
						+" INNER JOIN CTY_Vcl.dbo.Sys_FltISM as fi ON mfc.MsgFCo_FaultSPN = fi.SysISM_SPN AND mfc.MsgFCo_FaultFMI = fi.SysISM_FMI) "	
						+" ) bm inner join V_VehicleInfo v on v.VehicleID=bm.VehicleID "	
						+" where bm.MessageID> ? "	
						+" order by bm.MessageTime ";
			String amsgFId = "";
			String bmsgFId = "";
			for(Map<String,Object> msg:listID){
				if(MapGetter.getString(msg, "fltMR_DBName").toUpperCase().equals("A")){
					amsgFId = MapGetter.getString(msg, "MsgF_ID");
				}else{
					bmsgFId = MapGetter.getString(msg, "MsgF_ID");
				}
			}
			listA = baseDAO.execQuery(sql_A,
//					new Object[] {MapGetter.getString(listID.get(0), "MsgF_ID")});
					new Object[] {amsgFId});
					
			listB = baseDAO.execQuery(sql_B,
//					new Object[] {MapGetter.getString(listID.get(1), "MsgF_ID")});
					new Object[] {bmsgFId});
//			listB = baseDAO.execQuery(sql_B,
//					new Object[] {17799});
			/*calendar.add(Calendar.DATE, -1);
			toDay = sdf.format(calendar.getTime());
			String toDayT = sdfT.format(calendar.getTime());
			String sql2 = null;
			List<Map<String, Object>> list2 = null;
			for(Map<String,Object> mp : listB){
				if(sdfT.format(sdfT.parse(MapGetter.getString(mp, "MessageTime"))).equals(toDayT)){
					sql2 = "select MsgF_La=case when msgu_la IS null then p.MsgP_La else msgu_la end,MsgF_Lo=case when msgu_lo IS null then p.MsgP_Lo else msgu_lo end " +
			    			  "from CTY_Egn_B.dbo.Msg_UDS_"+toDay+
			    			  " left join CTY_Egn_B.dbo.Msg_PGN_"+toDay+" p  on MsgU_MsgTime=p.MsgP_MsgTime and MsgU_Vcl_ID=p.MsgP_Vcl_ID and MsgP_SysTI_ID=6  " +
			    			  "where MsgU_MsgTime ='"+MapGetter.getString(mp, "MessageTime")+"' and MsgP_MsgTime ='"+MapGetter.getString(mp, "MessageTime")+"' and MsgU_Vcl_ID = '"+MapGetter.getString(mp, "VehicleID")+"' and MsgP_Vcl_ID ='"+MapGetter.getString(mp, "VehicleID")+"' and MsgU_SysTI_ID=6 ";
					
					list2 = this.baseDAO.execQuery(sql2.toString(),new Object[] {});
					if(list2.size()>0){
						mp.put("MsgF_Lo", list2.get(0).get("MsgF_Lo"));
						mp.put("MsgF_La", list2.get(0).get("MsgF_La"));
					}
				}
			}
			*/
			for(Map<String,Object> mp2: listB){
				List<Map<String, Object>> lt = this.selectFltPosition2(MapGetter.getString(mp2, "MessageTime"), MapGetter.getString(mp2, "VehicleID"));
				if(null != lt && lt.size()>0 && StringUtil.isValid(lt.get(0).get("Msg_Lo")) && StringUtil.isValid(lt.get(0).get("Msg_La"))){
					mp2.put("MsgF_Lo", lt.get(0).get("Msg_Lo"));
					mp2.put("MsgF_La", lt.get(0).get("Msg_La"));
				}
			}
			
			
			//2.获取最大MessageID
			String maxID_A = getMaxId(listA);
			String maxID_B = getMaxId(listB);
			//3.保存MessageID为新的标记位
			String update_A = "update fltMsgRecord set fltMR_MsgF_ID=?,fltMR_UpdateTime=getDate()" +
					" where fltMR_DBName='A' and fltMR_TableName='Flt' ";
			String update_B = "update fltMsgRecord set fltMR_MsgF_ID=?,fltMR_UpdateTime=getDate()" +
					" where fltMR_DBName='B' and fltMR_TableName='Flt' " ;
			if(listA.size()>0)
				baseDAO.execUpdate(update_A, new Object[]{maxID_A});
			if(listB.size()>0)	
				baseDAO.execUpdate(update_B, new Object[]{maxID_B});
			listA.addAll(listB);
			listB = null;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return listA;
	}
	
	private String getMaxId(List<Map<String,Object>> fltList){
		if(fltList==null||fltList.size()==0){
			return "";
		}
		int maxId=0;
		for (Map<String, Object> map : fltList) {
			int msgID = Integer.parseInt(MapGetter.getString(map, "MessageID"));
			if(maxId<msgID)
				maxId = msgID;
		}
		return ""+maxId;
	}
	/**
	 * 获取故障信息所对应的位置
	 * @return
	 * @throws ParseException 
	 */
	public List<Map<String, Object>> selectFltPosition(String msgTime,String vehicleID) throws ParseException{
		StringBuffer sql = new StringBuffer();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat sdfT = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
        String toDay = sdf.format(calendar.getTime());
        String toDayT = sdfT.format(calendar.getTime());
        
        calendar.add(Calendar.DATE, -1);    //得到前一天
        String yeDay = sdf.format(calendar.getTime());
        String yeDayT = sdfT.format(calendar.getTime());
	    if(sdfT.format(sdfT.parse(msgTime)).equals(toDayT)){
	    	  sql.append( "from CTY_Egn_B.dbo.Msg_UDS_"+toDay+
	    			  " left join CTY_Egn_B.dbo.Msg_PGN_"+toDay+" p  on MsgU_MsgTime=p.MsgP_MsgTime and MsgU_Vcl_ID=p.MsgP_Vcl_ID and MsgP_SysTI_ID=6 " +
	    			  "where ((MsgU_La is not NULL and MsgU_Lo is not NULL) or (p.MsgP_La is not NULL and p.MsgP_Lo is not NULL)) " +
	    			  "and (MsgU_MsgTime ='"+msgTime+"' and p.MsgP_MsgTime='"+msgTime+"') and MsgU_Vcl_ID = '"+vehicleID+"'  and MsgU_SysTI_ID=6 ");  
		}
	    if(sdfT.format(sdfT.parse(msgTime)).equals(yeDayT)){
	    	sql.append( "from CTY_Egn_B.dbo.Msg_UDS_"+yeDay+
	    			  " left join CTY_Egn_B.dbo.Msg_PGN_"+yeDay+" p  on MsgU_MsgTime=p.MsgP_MsgTime and MsgU_Vcl_ID=p.MsgP_Vcl_ID and MsgP_SysTI_ID=6 " +
	    			  "where ((MsgU_La is not NULL and MsgU_Lo is not NULL) or (p.MsgP_La is not NULL and p.MsgP_Lo is not NULL)) " +
	    			  "and (MsgU_MsgTime ='"+msgTime+"' and p.MsgP_MsgTime='"+msgTime+"') and MsgU_Vcl_ID = '"+vehicleID+"' and MsgU_SysTI_ID=6");  
	    }
		List<Map<String, Object>> list = this.baseDAO.execQuery(sql.toString(),new Object[] {});
		
		return list;
	}
	
	public List<Map<String, Object>> selectFltPosition2(String msgTime,String vehicleID) throws ParseException{
		String sql = null;
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
		SimpleDateFormat sdfT = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();//此时打印它获取的是系统当前时间
        String toDay = sdf.format(calendar.getTime());
        String toDayT = sdfT.format(calendar.getTime());
        
        calendar.add(Calendar.DATE, -1);    //得到前一天
        String yeDay = sdf.format(calendar.getTime());
        String yeDayT = sdfT.format(calendar.getTime());
        List<Map<String, Object>> list = null;
        if(sdfT.format(sdfT.parse(msgTime)).equals(toDayT)){
	        sql = "select msgu_lo as msg_lo,msgu_la as msg_la from cty_egn_b.dbo.msg_uds_"+toDay+" where msgu_lo is not null and msgu_lo is not null and msgu_msgtime = '"+msgTime+"' AND msgu_vcl_id = '"+vehicleID+"' AND msgu_systi_id = 6 ";
	        list = this.baseDAO.execQuery(sql.toString(),new Object[] {});
	        if(null != list && list.size()>0){
	        	return list;
	        }else{
	        	sql = "select msgp_lo as msg_lo,msgp_la as msg_la  from cty_egn_b.dbo.msg_pgn_"+toDay+" where msgp_lo is not null and msgp_lo is not null and msgp_msgtime = '"+msgTime+"' AND msgp_vcl_id = '"+vehicleID+"' AND msgp_systi_id = 6 ";
	        	list = this.baseDAO.execQuery(sql.toString(),new Object[] {});
	        	if(null != list && list.size()>0){
	        		return list;
	        	}
	        }
        }
        if(sdfT.format(sdfT.parse(msgTime)).equals(yeDayT)){
        	sql = "select msgu_lo as msg_lo,msgu_la as msg_la  from cty_egn_b.dbo.msg_uds_"+yeDay+" where msgu_lo is not null and msgu_lo is not null and msgu_msgtime = '"+msgTime+"' AND msgu_vcl_id = '"+vehicleID+"' AND msgu_systi_id = 6 ";
	        list = this.baseDAO.execQuery(sql.toString(),new Object[] {});
	        if(null != list && list.size()>0){
	        	return list;
	        }else{
	        	sql = "select msgp_lo as msg_lo,msgp_la as msg_la  from cty_egn_b.dbo.msg_pgn_"+yeDay+" where msgp_lo is not null and msgp_lo is not null and msgp_msgtime = '"+msgTime+"' AND msgp_vcl_id = '"+vehicleID+"' AND msgp_systi_id = 6 ";
	        	list = this.baseDAO.execQuery(sql.toString(),new Object[] {});
	        	if(null != list && list.size()>0){
	        		return list;
	        	}
	        }
	    }
		return list;
	}
	/*从提示开关表中获取故障提示开关为关的设备号集合20141016wangkai
	 * 3.6.6新增
	 * vclpromptswitch:提示开关表
	 * VclPS_isOpen=0：开关状态为关
	 * VclPS_Type=1：提示开关类型为故障
	 * */
	public List<String> getFLtPromtPSwitch() {
		List<String> FltPromSwitch = new ArrayList<String>();
		
		String sql = "select VclPS_VclID from " +GlobalDBVar.getDBFullName_Conn("VclPromptSwitch","1",null)+
				" where VclPS_isOpen=0 and VclPS_Type=1 ";
		List<Map<String,Object>> list = baseDAO.execQuery(sql, new Object[]{});
		for (Map<String, Object> map : list) {
			FltPromSwitch.add(MapGetter.getString(map, "VclPS_VclID"));
		}
		return FltPromSwitch;
	}
	
	
	public List<Map<String,Object>> getAllUserMsg(int type){
		String sql="SELECT accountid,"+
				"as_deploycontent,"+
				"vehicleid,"+
				"vehiclenumber "+
				"FROM   adviceswitch aw "+
				"INNER JOIN v_userinfoaccount vuifa " +
				"ON aw.as_accountid = vuifa.accountid and AS_type = ? "+ 
				"INNER JOIN v_vehicleinfo vv "+
				" on vv.DBCode like vuifa.OrganizationCode+'%' ";
		List<Map<String,Object>> list=new ArrayList<Map<String,Object>>();
		list=baseDAO.execQuery(sql, new Object[]{type});
		return list;
	}
	//获取所有账户的百度id,频道id     
	public Map<String,Map<String,Object>> getAllAccountMsg(){
		String sql="select AccountID,baiduID_APP,bdChnID_APP,baiduID_APP_SP,bdChnID_APP_SP from V_SysUserInfoAccount";
		
		 Map<String,Map<String,Object>>  mapAll=new HashMap<String,Map<String,Object>>();
		List<Map<String,Object>> list=baseDAO.execQuery(sql, new Object[]{});
		for(Map<String,Object> map:list){
			String accountid=MapGetter.getString(map,"AccountID");
			mapAll.put(accountid, map);
		}
		return mapAll;
	}
	//现行故障  insert
	public void InsertFltMsg(Map<String,Map<String,Object>> fltTimesMaps,List<String> sqlListone,List<Object[]> paramListone){
		for(Iterator<String> it=fltTimesMaps.keySet().iterator();it.hasNext();){
			String key=it.next();
			Map<String,Object> mapValue=fltTimesMaps.get(key);
			String spn=MapGetter.getString(mapValue, "SysISM_SPN" );
			String fmi=MapGetter.getString(mapValue,"SysISM_FMI");
			String MessageTime=MapGetter.getString(mapValue, "MessageTime");
			String fltTimes = MapGetter.getString(mapValue,"fltTimes");
			String vclId = MapGetter.getString(mapValue, "VehicleID");//设备id.
			String delsql="delete from Msg_Flt_HappeningLast where MsgFH_Vcl_ID=? and MsgFH_FaultSPN=? and MsgFH_FaultFMI=?";
			sqlListone.add(delsql);
			paramListone.add(new String[]{vclId,spn,fmi});
			String insertSql="insert into Msg_Flt_HappeningLast(MsgFH_Vcl_ID,MsgFH_MsgTime,MsgFH_FaultSPN,MsgFH_FaultFMI,MsgFH_FltCount) values (?,?,?,?,?)";
			sqlListone.add(insertSql);
			paramListone.add(new String[]{vclId,MessageTime,spn,fmi,fltTimes});	
		}
	}
	//非现行故障删除
	public 	void delFltMsg(Map<String,Map<String,Object>> NofltTimesMaps,List<String> sqlListone,List<Object[]> paramListone){
		for(Iterator<String> it=NofltTimesMaps.keySet().iterator();it.hasNext();){
			String key=it.next();
			Map<String,Object> mapValue=NofltTimesMaps.get(key);
			String spn=MapGetter.getString(mapValue, "SysISM_SPN" );
			String fmi=MapGetter.getString(mapValue,"SysISM_FMI");
			String vclId = MapGetter.getString(mapValue, "VehicleID");//设备id.
			String delsql="delete from Msg_Flt_HappeningLast where MsgFH_Vcl_ID=? and MsgFH_FaultSPN=? and MsgFH_FaultFMI=?";
			sqlListone.add(delsql);
			paramListone.add(new String[]{vclId,spn,fmi});
			
		}
	}
}

